Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azure-json Updates #34279

Merged
merged 6 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,8 @@ the main ServiceBusClientBuilder. -->
<!-- Field additionallyAllowedTenants is not set in constructor and can be changed using the builder option. -->
<suppress checks="com.azure.tools.checkstyle.checks.EnforceFinalFieldsCheck" files="com.azure.identity.DefaultAzureCredentialBuilder"/>

<suppress checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" files=".*(DeviceCodeCredential|InteractiveBrowserCredential|AzureCliCredential|AzureDeveloperCliCredential|ClientCertificateCredential|ClientSecretCredential|EnvironmentCredential|OnBehalfOfCredential|ChainedTokenCredential|ClientAssertionCredential|UsernamePasswordCredential).java"/>
<suppress checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" files=".*(DeviceCodeCredential|InteractiveBrowserCredential|AzureCliCredential|AzureDeveloperCliCredential|ClientCertificateCredential|ClientSecretCredential|EnvironmentCredential|OnBehalfOfCredential|ChainedTokenCredential|ClientAssertionCredential|UsernamePasswordCredential).java"/>

<suppress checks="com.azure.tools.checkstyle.checks.EnforceFinalFieldsCheck" files="com.azure.search.documents.indexes.models.SynonymMap"/>

</suppressions>
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public JsonReader bufferObject() throws IOException {
}

@Override
public boolean resetSupported() {
public boolean isResetSupported() {
return resetSupported;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public JsonReader bufferObject() throws IOException {
}

@Override
public boolean resetSupported() {
public boolean isResetSupported() {
return resetSupported;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public JsonReader bufferObject() throws IOException {
}

@Override
public boolean resetSupported() {
public boolean isResetSupported() {
return this.resetSupported;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.json.reflect;

import com.azure.json.JsonOptions;
import com.azure.json.JsonReader;
import com.azure.json.contract.JsonReaderContractTests;

Expand All @@ -14,6 +15,6 @@
public class GsonJsonReaderContractTests extends JsonReaderContractTests {
@Override
public JsonReader getJsonReader(String json) throws IOException {
return JsonProviderFactory.getGsonJsonProvider().createReader(json);
return JsonProviderFactory.getGsonJsonProvider().createReader(json, new JsonOptions());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.json.reflect;

import com.azure.json.JsonOptions;
import com.azure.json.JsonWriter;
import com.azure.json.contract.JsonWriterContractTests;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -21,7 +22,7 @@ public class GsonJsonWriterContractTests extends JsonWriterContractTests {
@BeforeEach
public void beforeEach() throws IOException {
this.outputStream = new ByteArrayOutputStream();
this.writer = JsonProviderFactory.getGsonJsonProvider().createWriter(outputStream);
this.writer = JsonProviderFactory.getGsonJsonProvider().createWriter(outputStream, new JsonOptions());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.json.reflect;

import com.azure.json.JsonOptions;
import com.azure.json.JsonReader;
import com.azure.json.contract.JsonReaderContractTests;

Expand All @@ -14,6 +15,6 @@
public class JacksonJsonReaderContractTests extends JsonReaderContractTests {
@Override
public JsonReader getJsonReader(String json) throws IOException {
return JsonProviderFactory.getJacksonJsonProvider().createReader(json);
return JsonProviderFactory.getJacksonJsonProvider().createReader(json, new JsonOptions());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.json.reflect;

import com.azure.json.JsonOptions;
import com.azure.json.JsonWriter;
import com.azure.json.contract.JsonWriterContractTests;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -21,7 +22,7 @@ public class JacksonJsonWriterContractTests extends JsonWriterContractTests {
@BeforeEach
public void beforeEach() throws IOException {
this.outputStream = new ByteArrayOutputStream();
this.writer = JsonProviderFactory.getJacksonJsonProvider().createWriter(outputStream);
this.writer = JsonProviderFactory.getJacksonJsonProvider().createWriter(outputStream, new JsonOptions());
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion sdk/core/azure-json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<version>1.0.0-beta.4</version> <!-- {x-version-update;com.azure:azure-json;current} -->

<name>Microsoft Azure Java JSON Library</name>
<description>This package contains core types for JSON.</description>
<description>This package provides interfaces for reading and writing JSON.</description>
<url>https://github.com/Azure/azure-sdk-for-java</url>

<licenses>
Expand Down Expand Up @@ -57,6 +57,8 @@
<javadoc.excludePackageNames/>
<javadoc.sourcepath>${basedir}/src/main/java</javadoc.sourcepath>

<jacoco.min.linecoverage>0.85</jacoco.min.linecoverage>
<jacoco.min.branchcoverage>0.75</jacoco.min.branchcoverage>
</properties>

<developers>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* Contains configuration options for creating a {@link JsonReader} or {@link JsonWriter}.
*/
public final class JsonOptions {
static final JsonOptions DEFAULT_OPTIONS = new JsonOptions();

private boolean nonNumericNumbersSupported = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,140 +14,69 @@
* {@link JsonWriter} implementation.
*/
public interface JsonProvider {
/**
* Creates an instance of {@link JsonReader} that reads a {@code byte[]}.
*
* @param json The JSON represented as a {@code byte[]}.
* @return A new instance of {@link JsonReader}.
* @throws NullPointerException If {@code json} is null.
* @throws IOException If a {@link JsonReader} cannot be instantiated.
*/
default JsonReader createReader(byte[] json) throws IOException {
return createReader(json, JsonOptions.DEFAULT_OPTIONS);
}

/**
* Creates an instance of {@link JsonReader} that reads a {@code byte[]}.
*
* @param json The JSON represented as a {@code byte[]}.
* @param options {@link JsonOptions} to configure the creation of the {@link JsonReader}.
* @return A new instance of {@link JsonReader}.
* @throws NullPointerException If {@code json} is null.
* @throws NullPointerException If {@code json} or {@code options} is null.
* @throws IOException If a {@link JsonReader} cannot be instantiated.
*/
JsonReader createReader(byte[] json, JsonOptions options) throws IOException;

/**
* Creates an instance of {@link JsonReader} that reads a {@link String}.
*
* @param json The JSON represented as a {@link String}.
* @return A new instance of {@link JsonReader}.
* @throws NullPointerException If {@code json} is null.
* @throws IOException If a {@link JsonReader} cannot be instantiated.
*/
default JsonReader createReader(String json) throws IOException {
return createReader(json, JsonOptions.DEFAULT_OPTIONS);
}

/**
* Creates an instance of {@link JsonReader} that reads a {@link String}.
*
* @param json The JSON represented as a {@link String}.
* @param options {@link JsonOptions} to configure the creation of the {@link JsonReader}.
* @return A new instance of {@link JsonReader}.
* @throws NullPointerException If {@code json} is null.
* @throws NullPointerException If {@code json} or {@code options} is null.
* @throws IOException If a {@link JsonReader} cannot be instantiated.
*/
JsonReader createReader(String json, JsonOptions options) throws IOException;

/**
* Creates an instance of {@link JsonReader} that reads a {@link InputStream}.
*
* @param json The JSON represented as a {@link InputStream}.
* @return A new instance of {@link JsonReader}.
* @throws NullPointerException If {@code json} is null.
* @throws IOException If a {@link JsonReader} cannot be instantiated.
*/
default JsonReader createReader(InputStream json) throws IOException {
return createReader(json, JsonOptions.DEFAULT_OPTIONS);
}

/**
* Creates an instance of {@link JsonReader} that reads a {@link InputStream}.
*
* @param json The JSON represented as a {@link InputStream}.
* @param options {@link JsonOptions} to configure the creation of the {@link JsonReader}.
* @return A new instance of {@link JsonReader}.
* @throws NullPointerException If {@code json} is null.
* @throws NullPointerException If {@code json} or {@code options} is null.
* @throws IOException If a {@link JsonReader} cannot be instantiated.
*/
JsonReader createReader(InputStream json, JsonOptions options) throws IOException;

/**
* Creates an instance of {@link JsonReader} that reads a {@link Reader}.
*
* @param json The JSON represented as a {@link Reader}.
* @return A new instance of {@link JsonReader}.
* @throws NullPointerException If {@code json} is null.
* @throws IOException If a {@link JsonReader} cannot be instantiated.
*/
default JsonReader createReader(Reader json) throws IOException {
return createReader(json, JsonOptions.DEFAULT_OPTIONS);
}

/**
* Creates an instance of {@link JsonReader} that reads a {@link Reader}.
*
* @param json The JSON represented as a {@link Reader}.
* @param options {@link JsonOptions} to configure the creation of the {@link JsonReader}.
* @return A new instance of {@link JsonReader}.
* @throws NullPointerException If {@code json} is null.
* @throws NullPointerException If {@code json} or {@code options} is null.
* @throws IOException If a {@link JsonReader} cannot be instantiated.
*/
JsonReader createReader(Reader json, JsonOptions options) throws IOException;

/**
* Creates an instance of {@link JsonWriter} that writes to an {@link OutputStream}.
*
* @param json The JSON represented as an {@link OutputStream}.
* @return A new instance of {@link JsonWriter}.
* @throws NullPointerException If {@code json} is null.
* @throws IOException If a {@link JsonReader} cannot be instantiated.
*/
default JsonWriter createWriter(OutputStream json) throws IOException {
return createWriter(json, JsonOptions.DEFAULT_OPTIONS);
}

/**
* Creates an instance of {@link JsonWriter} that writes to an {@link OutputStream}.
*
* @param json The JSON represented as an {@link OutputStream}.
* @param options {@link JsonOptions} to configure the creation of the {@link JsonWriter}.
* @return A new instance of {@link JsonWriter}.
* @throws NullPointerException If {@code json} is null.
* @throws NullPointerException If {@code json} or {@code options} is null.
* @throws IOException If a {@link JsonReader} cannot be instantiated.
*/
JsonWriter createWriter(OutputStream json, JsonOptions options) throws IOException;

/**
* Creates an instance of {@link JsonWriter} that writes to an {@link Writer}.
*
* @param json The JSON represented as an {@link Writer}.
* @return A new instance of {@link JsonWriter}.
* @throws NullPointerException If {@code json} is null.
* @throws IOException If a {@link JsonReader} cannot be instantiated.
*/
default JsonWriter createWriter(Writer json) throws IOException {
return createWriter(json, JsonOptions.DEFAULT_OPTIONS);
}

/**
* Creates an instance of {@link JsonWriter} that writes to an {@link Writer}.
*
* @param json The JSON represented as an {@link Writer}.
* @param options {@link JsonOptions} to configure the creation of the {@link JsonWriter}.
* @return A new instance of {@link JsonWriter}.
* @throws NullPointerException If {@code json} is null.
* @throws NullPointerException If {@code json} or {@code options} is null.
* @throws IOException If a {@link JsonReader} cannot be instantiated.
*/
JsonWriter createWriter(Writer json, JsonOptions options) throws IOException;
Expand Down
Loading