Skip to content

Commit

Permalink
Merge branch 'main' into fix_default_handler_overide
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet committed Oct 11, 2024
2 parents fe5211e + 731286c commit 48beda2
Show file tree
Hide file tree
Showing 22 changed files with 531 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.5.1"
".": "1.6.0"
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.6.0](https://github.com/microsoft/kiota-java/compare/v1.5.1...v1.6.0) (2024-10-08)


### Features

* Adds overload to serialization proxy factories to configure serialization of all values in backed models ([867953c](https://github.com/microsoft/kiota-java/commit/867953cbd0523cd8d146a5f3a522cd8652ccd924))
* Adds overloads to serialization helper methods with backing store serialization configuration options ([0006ff8](https://github.com/microsoft/kiota-java/commit/0006ff8538e2c26692c4e2f3238fadaec1436027))

## [1.5.1](https://github.com/microsoft/kiota-java/compare/v1.5.0...v1.5.1) (2024-10-03)


Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@ In `build.gradle` in the `dependencies` section:

```Groovy
// x-release-please-start-version
implementation 'com.microsoft.kiota:microsoft-kiota-abstractions:1.5.1'
implementation 'com.microsoft.kiota:microsoft-kiota-abstractions:1.6.0'
// x-release-please-end
implementation 'com.microsoft.kiota:microsoft-kiota-authentication-azure:1.5.0'
// x-release-please-end
// x-release-please-start-version
implementation 'com.microsoft.kiota:microsoft-kiota-http-okHttp:1.5.1'
implementation 'com.microsoft.kiota:microsoft-kiota-http-okHttp:1.6.0'
// x-release-please-end
// x-release-please-start-version
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-json:1.5.1'
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-json:1.6.0'
// x-release-please-end
// x-release-please-start-version
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-text:1.5.1'
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-text:1.6.0'
// x-release-please-end
// x-release-please-start-version
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-form:1.5.1'
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-form:1.6.0'
// x-release-please-end
// x-release-please-start-version
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-multipart:1.5.1'
implementation 'com.microsoft.kiota:microsoft-kiota-serialization-multipart:1.6.0'
// x-release-please-end
// x-release-please-start-version
implementation 'com.microsoft.kiota:microsoft-kiota-bundle:1.5.1'
implementation 'com.microsoft.kiota:microsoft-kiota-bundle:1.6.0'
// x-release-please-end
implementation 'jakarta.annotation:jakarta.annotation-api:2.1.1'
```
Expand All @@ -56,49 +56,49 @@ In `pom.xml` in the `dependencies` section:
<groupId>com.microsoft.kiota</groupId>
<artifactId>microsoft-kiota-abstractions</artifactId>
<!--x-release-please-start-version-->
<version>1.5.1</version>
<version>1.6.0</version>
<!--x-release-please-end-->
</dependency>
<dependency>
<groupId>com.microsoft.kiota</groupId>
<artifactId>microsoft-kiota-authentication-azure</artifactId>
<!--x-release-please-start-version-->
<version>1.5.1</version>
<version>1.6.0</version>
<!--x-release-please-end-->
</dependency>
<dependency>
<groupId>com.microsoft.kiota</groupId>
<artifactId>microsoft-kiota-http-okHttp</artifactId>
<!--x-release-please-start-version-->
<version>1.5.1</version>
<version>1.6.0</version>
<!--x-release-please-end-->
</dependency>
<dependency>
<groupId>com.microsoft.kiota</groupId>
<artifactId>microsoft-kiota-serialization-json</artifactId>
<!--x-release-please-start-version-->
<version>1.5.1</version>
<version>1.6.0</version>
<!--x-release-please-end-->
</dependency>
<dependency>
<groupId>com.microsoft.kiota</groupId>
<artifactId>microsoft-kiota-serialization-text</artifactId>
<!--x-release-please-start-version-->
<version>1.5.1</version>
<version>1.6.0</version>
<!--x-release-please-end-->
</dependency>
<dependency>
<groupId>com.microsoft.kiota</groupId>
<artifactId>microsoft-kiota-serialization-form</artifactId>
<!--x-release-please-start-version-->
<version>1.5.1</version>
<version>1.6.0</version>
<!--x-release-please-end-->
</dependency>
<dependency>
<groupId>com.microsoft.kiota</groupId>
<artifactId>microsoft-kiota-serialization-multipart</artifactId>
<!--x-release-please-start-version-->
<version>1.5.1</version>
<version>1.6.0</version>
<!--x-release-please-end-->
</dependency>
<dependency>
Expand Down
1 change: 1 addition & 0 deletions components/abstractions/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ android {
disable "GradleDependency"
disable "NewerVersionAvailable"
disable "DuplicatePlatformClasses" // xpp3 added by azure-identity
disable "LambdaLast" // Wrongly enforced in KiotaJsonSerialization helpers
}
sourceSets {
main {
Expand Down
5 changes: 3 additions & 2 deletions components/abstractions/gradle/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
dependencies {
// Use JUnit Jupiter API for testing.
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.1'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.11.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.11.2'
testImplementation 'org.mockito:mockito-core:5.14.1'
testImplementation project(':components:serialization:json')

// Use JUnit Jupiter Engine for testing.
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
Expand Down
6 changes: 2 additions & 4 deletions components/abstractions/spotBugsExcludeFilter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubu
<Bug pattern="RV_EXCEPTION_NOT_THROWN"/>
<Class name="com.microsoft.kiota.serialization.SerializationHelpersTest" />
</Match>
<Match>
<Bug pattern="EI_EXPOSE_REP" />
<Class name="com.microsoft.kiota.serialization.mocks.TestEntity" />
</Match>
<Match>
<Bug pattern="EI_EXPOSE_REP" />
<Or>
<Class name="com.microsoft.kiota.serialization.mocks.TestEntity" />
<Class name="com.microsoft.kiota.serialization.mocks.TestBackedModelEntity" />
<Class name="com.microsoft.kiota.TestEntity" />
<Class name="com.microsoft.kiota.BaseCollectionPaginationCountResponse" />
</Or>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ private KiotaJsonSerialization() {}
return KiotaSerialization.serializeAsStream(CONTENT_TYPE, value);
}

/**
* Serializes the given value to a stream
* @param <T> the type of the value to serialize
* @param value the value to serialize
* @param serializeOnlyChangedValues whether to serialize all values in value if value is a BackedModel
* @return the serialized value as a stream
* @throws IOException when the stream cannot be closed or read.
*/
@Nonnull public static <T extends Parsable> InputStream serializeAsStream(
@Nonnull final T value, final boolean serializeOnlyChangedValues) throws IOException {
return KiotaSerialization.serializeAsStream(
CONTENT_TYPE, value, serializeOnlyChangedValues);
}

/**
* Serializes the given value to a string
* @param <T> the type of the value to serialize
Expand All @@ -38,6 +52,20 @@ private KiotaJsonSerialization() {}
return KiotaSerialization.serializeAsString(CONTENT_TYPE, value);
}

/**
* Serializes the given value to a string
* @param <T> the type of the value to serialize
* @param value the value to serialize
* @param serializeOnlyChangedValues whether to serialize all values in value if value is a BackedModel
* @return the serialized value as a string
* @throws IOException when the stream cannot be closed or read.
*/
@Nonnull public static <T extends Parsable> String serializeAsString(
@Nonnull final T value, final boolean serializeOnlyChangedValues) throws IOException {
return KiotaSerialization.serializeAsString(
CONTENT_TYPE, value, serializeOnlyChangedValues);
}

/**
* Serializes the given value to a stream
* @param <T> the type of the value to serialize
Expand All @@ -50,6 +78,21 @@ private KiotaJsonSerialization() {}
return KiotaSerialization.serializeAsStream(CONTENT_TYPE, values);
}

/**
* Serializes the given value to a stream
* @param <T> the type of the value to serialize
* @param values the values to serialize
* @param serializeOnlyChangedValues whether to serialize all values in value if value is a BackedModel
* @return the serialized value as a stream
* @throws IOException when the stream cannot be closed or read.
*/
@Nonnull public static <T extends Parsable> InputStream serializeAsStream(
@Nonnull final Iterable<T> values, final boolean serializeOnlyChangedValues)
throws IOException {
return KiotaSerialization.serializeAsStream(
CONTENT_TYPE, values, serializeOnlyChangedValues);
}

/**
* Serializes the given value to a string
* @param <T> the type of the value to serialize
Expand All @@ -62,6 +105,21 @@ private KiotaJsonSerialization() {}
return KiotaSerialization.serializeAsString(CONTENT_TYPE, values);
}

/**
* Serializes the given value to a string
* @param <T> the type of the value to serialize
* @param values the values to serialize
* @param serializeOnlyChangedValues whether to serialize all values in value if value is a BackedModel
* @return the serialized value as a string
* @throws IOException when the stream cannot be closed or read.
*/
@Nonnull public static <T extends Parsable> String serializeAsString(
@Nonnull final Iterable<T> values, final boolean serializeOnlyChangedValues)
throws IOException {
return KiotaSerialization.serializeAsString(
CONTENT_TYPE, values, serializeOnlyChangedValues);
}

/**
* Deserializes the given stream to a model object
* @param <T> the type of the value to deserialize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
public final class KiotaSerialization {
private static final String CHARSET_NAME = "UTF-8";
private static final boolean DEFAULT_SERIALIZE_ONLY_CHANGED_VALUES = true;

private KiotaSerialization() {}

Expand All @@ -29,7 +30,26 @@ private KiotaSerialization() {}
*/
@Nonnull public static <T extends Parsable> InputStream serializeAsStream(
@Nonnull final String contentType, @Nonnull final T value) throws IOException {
try (final SerializationWriter writer = getSerializationWriter(contentType, value)) {
return serializeAsStream(contentType, value, DEFAULT_SERIALIZE_ONLY_CHANGED_VALUES);
}

/**
* Serializes the given value to a stream and configures returned values by the backing store if available
* @param <T> the type of the value to serialize
* @param contentType the content type to use for serialization
* @param value the value to serialize
* @param serializeOnlyChangedValues whether to serialize all values in value if value is a BackedModel
* @return the serialized value as a stream
* @throws IOException when the stream cannot be closed or read.
*/
@Nonnull public static <T extends Parsable> InputStream serializeAsStream(
@Nonnull final String contentType,
@Nonnull final T value,
final boolean serializeOnlyChangedValues)
throws IOException {
Objects.requireNonNull(value);
try (final SerializationWriter writer =
getSerializationWriter(contentType, serializeOnlyChangedValues)) {
writer.writeObjectValue("", value);
return writer.getSerializedContent();
}
Expand All @@ -45,7 +65,27 @@ private KiotaSerialization() {}
*/
@Nonnull public static <T extends Parsable> String serializeAsString(
@Nonnull final String contentType, @Nonnull final T value) throws IOException {
try (final InputStream stream = serializeAsStream(contentType, value)) {
Objects.requireNonNull(value);
return serializeAsString(contentType, value, DEFAULT_SERIALIZE_ONLY_CHANGED_VALUES);
}

/**
* Serializes the given value to a string
* @param <T> the type of the value to serialize
* @param contentType the content type to use for serialization
* @param value the value to serialize
* @param serializeOnlyChangedValues whether to serialize all values in value if value is a BackedModel
* @return the serialized value as a string
* @throws IOException when the stream cannot be closed or read.
*/
@Nonnull public static <T extends Parsable> String serializeAsString(
@Nonnull final String contentType,
@Nonnull final T value,
final boolean serializeOnlyChangedValues)
throws IOException {
Objects.requireNonNull(value);
try (final InputStream stream =
serializeAsStream(contentType, value, serializeOnlyChangedValues)) {
return new String(Compatibility.readAllBytes(stream), CHARSET_NAME);
}
}
Expand All @@ -61,7 +101,27 @@ private KiotaSerialization() {}
@Nonnull public static <T extends Parsable> InputStream serializeAsStream(
@Nonnull final String contentType, @Nonnull final Iterable<T> values)
throws IOException {
try (final SerializationWriter writer = getSerializationWriter(contentType, values)) {
Objects.requireNonNull(values);
return serializeAsStream(contentType, values, DEFAULT_SERIALIZE_ONLY_CHANGED_VALUES);
}

/**
* Serializes the given value to a stream
* @param <T> the type of the value to serialize
* @param contentType the content type to use for serialization
* @param values the values to serialize
* @param serializeOnlyChangedValues whether to serialize all values in value if value is a BackedModel
* @return the serialized value as a stream
* @throws IOException when the stream cannot be closed or read.
*/
@Nonnull public static <T extends Parsable> InputStream serializeAsStream(
@Nonnull final String contentType,
@Nonnull final Iterable<T> values,
final boolean serializeOnlyChangedValues)
throws IOException {
Objects.requireNonNull(values);
try (final SerializationWriter writer =
getSerializationWriter(contentType, serializeOnlyChangedValues)) {
writer.writeCollectionOfObjectValues("", values);
return writer.getSerializedContent();
}
Expand All @@ -78,20 +138,39 @@ private KiotaSerialization() {}
@Nonnull public static <T extends Parsable> String serializeAsString(
@Nonnull final String contentType, @Nonnull final Iterable<T> values)
throws IOException {
try (final InputStream stream = serializeAsStream(contentType, values)) {
Objects.requireNonNull(values);
return serializeAsString(contentType, values, DEFAULT_SERIALIZE_ONLY_CHANGED_VALUES);
}

/**
* Serializes the given value to a string
* @param <T> the type of the value to serialize
* @param contentType the content type to use for serialization
* @param values the values to serialize
* @param serializeOnlyChangedValues whether to serialize all values in value if value is a BackedModel
* @return the serialized value as a string
* @throws IOException when the stream cannot be closed or read.
*/
@Nonnull public static <T extends Parsable> String serializeAsString(
@Nonnull final String contentType,
@Nonnull final Iterable<T> values,
final boolean serializeOnlyChangedValues)
throws IOException {
Objects.requireNonNull(values);
try (final InputStream stream =
serializeAsStream(contentType, values, serializeOnlyChangedValues)) {
return new String(Compatibility.readAllBytes(stream), CHARSET_NAME);
}
}

private static SerializationWriter getSerializationWriter(
@Nonnull final String contentType, @Nonnull final Object value) {
@Nonnull final String contentType, final boolean serializeOnlyChangedValues) {
Objects.requireNonNull(contentType);
Objects.requireNonNull(value);
if (contentType.isEmpty()) {
throw new NullPointerException("content type cannot be empty");
}
return SerializationWriterFactoryRegistry.defaultInstance.getSerializationWriter(
contentType);
contentType, serializeOnlyChangedValues);
}

/**
Expand Down
Loading

0 comments on commit 48beda2

Please sign in to comment.