Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: microsoft/kiota-java
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.5.1
Choose a base ref
...
head repository: microsoft/kiota-java
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.6.0
Choose a head ref
  • 17 commits
  • 22 files changed
  • 4 contributors

Commits on Oct 3, 2024

  1. feat: Adds overload to serialization proxy factories to configure ser…

    …ialization of all values in backed models
    Ndiritu committed Oct 3, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    867953c View commit details
  2. feat: Adds overloads to serialization helper methods with backing sto…

    …re serialization configuration options
    Ndiritu committed Oct 3, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    0006ff8 View commit details

Commits on Oct 4, 2024

  1. Add unit tests

    Ndiritu committed Oct 4, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    1a6738b View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    3b96a38 View commit details
  3. Fix android linting failures

    Ndiritu committed Oct 4, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    aac05d3 View commit details
  4. Increase test coverage

    Ndiritu committed Oct 4, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    bc6edc4 View commit details
  5. Fix spotless failures

    Ndiritu committed Oct 4, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    0c843ab View commit details
  6. Fix sonarcloud issues

    Ndiritu committed Oct 4, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    4837b52 View commit details

Commits on Oct 7, 2024

  1. chore(deps): bump the junit-dependencies group across 8 directories w…

    …ith 2 updates
    
    Bumps the junit-dependencies group with 2 updates in the /components/abstractions directory: [org.junit.jupiter:junit-jupiter-api](https://github.com/junit-team/junit5) and [org.junit.jupiter:junit-jupiter-params](https://github.com/junit-team/junit5).
    Bumps the junit-dependencies group with 2 updates in the /components/authentication/azure directory: [org.junit.jupiter:junit-jupiter-api](https://github.com/junit-team/junit5) and [org.junit.jupiter:junit-jupiter-params](https://github.com/junit-team/junit5).
    Bumps the junit-dependencies group with 2 updates in the /components/bundle directory: [org.junit.jupiter:junit-jupiter-api](https://github.com/junit-team/junit5) and [org.junit.jupiter:junit-jupiter-params](https://github.com/junit-team/junit5).
    Bumps the junit-dependencies group with 2 updates in the /components/http/okHttp directory: [org.junit.jupiter:junit-jupiter-api](https://github.com/junit-team/junit5) and [org.junit.jupiter:junit-jupiter-params](https://github.com/junit-team/junit5).
    Bumps the junit-dependencies group with 2 updates in the /components/serialization/form directory: [org.junit.jupiter:junit-jupiter-api](https://github.com/junit-team/junit5) and [org.junit.jupiter:junit-jupiter-params](https://github.com/junit-team/junit5).
    Bumps the junit-dependencies group with 2 updates in the /components/serialization/json directory: [org.junit.jupiter:junit-jupiter-api](https://github.com/junit-team/junit5) and [org.junit.jupiter:junit-jupiter-params](https://github.com/junit-team/junit5).
    Bumps the junit-dependencies group with 1 update in the /components/serialization/multipart directory: [org.junit.jupiter:junit-jupiter-api](https://github.com/junit-team/junit5).
    Bumps the junit-dependencies group with 2 updates in the /components/serialization/text directory: [org.junit.jupiter:junit-jupiter-api](https://github.com/junit-team/junit5) and [org.junit.jupiter:junit-jupiter-params](https://github.com/junit-team/junit5).
    
    
    Updates `org.junit.jupiter:junit-jupiter-api` from 5.11.1 to 5.11.2
    - [Release notes](https://github.com/junit-team/junit5/releases)
    - [Commits](junit-team/junit5@r5.11.1...r5.11.2)
    
    Updates `org.junit.jupiter:junit-jupiter-params` from 5.11.1 to 5.11.2
    - [Release notes](https://github.com/junit-team/junit5/releases)
    - [Commits](junit-team/junit5@r5.11.1...r5.11.2)
    
    Updates `org.junit.jupiter:junit-jupiter-api` from 5.11.1 to 5.11.2
    - [Release notes](https://github.com/junit-team/junit5/releases)
    - [Commits](junit-team/junit5@r5.11.1...r5.11.2)
    
    Updates `org.junit.jupiter:junit-jupiter-params` from 5.11.1 to 5.11.2
    - [Release notes](https://github.com/junit-team/junit5/releases)
    - [Commits](junit-team/junit5@r5.11.1...r5.11.2)
    
    Updates `org.junit.jupiter:junit-jupiter-api` from 5.11.1 to 5.11.2
    - [Release notes](https://github.com/junit-team/junit5/releases)
    - [Commits](junit-team/junit5@r5.11.1...r5.11.2)
    
    Updates `org.junit.jupiter:junit-jupiter-params` from 5.11.1 to 5.11.2
    - [Release notes](https://github.com/junit-team/junit5/releases)
    - [Commits](junit-team/junit5@r5.11.1...r5.11.2)
    
    Updates `org.junit.jupiter:junit-jupiter-api` from 5.11.1 to 5.11.2
    - [Release notes](https://github.com/junit-team/junit5/releases)
    - [Commits](junit-team/junit5@r5.11.1...r5.11.2)
    
    Updates `org.junit.jupiter:junit-jupiter-params` from 5.11.1 to 5.11.2
    - [Release notes](https://github.com/junit-team/junit5/releases)
    - [Commits](junit-team/junit5@r5.11.1...r5.11.2)
    
    Updates `org.junit.jupiter:junit-jupiter-api` from 5.11.1 to 5.11.2
    - [Release notes](https://github.com/junit-team/junit5/releases)
    - [Commits](junit-team/junit5@r5.11.1...r5.11.2)
    
    Updates `org.junit.jupiter:junit-jupiter-params` from 5.11.1 to 5.11.2
    - [Release notes](https://github.com/junit-team/junit5/releases)
    - [Commits](junit-team/junit5@r5.11.1...r5.11.2)
    
    Updates `org.junit.jupiter:junit-jupiter-api` from 5.11.1 to 5.11.2
    - [Release notes](https://github.com/junit-team/junit5/releases)
    - [Commits](junit-team/junit5@r5.11.1...r5.11.2)
    
    Updates `org.junit.jupiter:junit-jupiter-params` from 5.11.1 to 5.11.2
    - [Release notes](https://github.com/junit-team/junit5/releases)
    - [Commits](junit-team/junit5@r5.11.1...r5.11.2)
    
    Updates `org.junit.jupiter:junit-jupiter-api` from 5.11.1 to 5.11.2
    - [Release notes](https://github.com/junit-team/junit5/releases)
    - [Commits](junit-team/junit5@r5.11.1...r5.11.2)
    
    Updates `org.junit.jupiter:junit-jupiter-api` from 5.11.1 to 5.11.2
    - [Release notes](https://github.com/junit-team/junit5/releases)
    - [Commits](junit-team/junit5@r5.11.1...r5.11.2)
    
    Updates `org.junit.jupiter:junit-jupiter-params` from 5.11.1 to 5.11.2
    - [Release notes](https://github.com/junit-team/junit5/releases)
    - [Commits](junit-team/junit5@r5.11.1...r5.11.2)
    
    ---
    updated-dependencies:
    - dependency-name: org.junit.jupiter:junit-jupiter-api
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: junit-dependencies
    - dependency-name: org.junit.jupiter:junit-jupiter-params
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: junit-dependencies
    - dependency-name: org.junit.jupiter:junit-jupiter-api
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: junit-dependencies
    - dependency-name: org.junit.jupiter:junit-jupiter-params
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: junit-dependencies
    - dependency-name: org.junit.jupiter:junit-jupiter-api
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: junit-dependencies
    - dependency-name: org.junit.jupiter:junit-jupiter-params
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: junit-dependencies
    - dependency-name: org.junit.jupiter:junit-jupiter-api
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: junit-dependencies
    - dependency-name: org.junit.jupiter:junit-jupiter-params
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: junit-dependencies
    - dependency-name: org.junit.jupiter:junit-jupiter-api
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: junit-dependencies
    - dependency-name: org.junit.jupiter:junit-jupiter-params
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: junit-dependencies
    - dependency-name: org.junit.jupiter:junit-jupiter-api
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: junit-dependencies
    - dependency-name: org.junit.jupiter:junit-jupiter-params
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: junit-dependencies
    - dependency-name: org.junit.jupiter:junit-jupiter-api
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: junit-dependencies
    - dependency-name: org.junit.jupiter:junit-jupiter-api
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: junit-dependencies
    - dependency-name: org.junit.jupiter:junit-jupiter-params
      dependency-type: direct:production
      update-type: version-update:semver-patch
      dependency-group: junit-dependencies
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored Oct 7, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    68f6bf3 View commit details
  2. Merge pull request #1610 from microsoft/dependabot/gradle/components/…

    …abstractions/junit-dependencies-f396f7d5d6
    
    chore(deps): bump the junit-dependencies group across 8 directories with 2 updates
    github-actions[bot] authored Oct 7, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    ce707fc View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d5dc8f9 View commit details
  4. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    5922c54 View commit details
  5. Rename protected variable

    Ndiritu committed Oct 7, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    81d3b24 View commit details
  6. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    6a8b996 View commit details

Commits on Oct 8, 2024

  1. Merge pull request #1608 from microsoft/fix/serialization-helper-back…

    …ing-store
    
    Allow backing store serialization configuration in serialization helpers
    Ndiritu authored Oct 8, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d15e201 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    2a767f0 View commit details
  3. Merge pull request #1611 from microsoft/release-please--branches--main

    chore(main): release 1.6.0
    Ndiritu authored Oct 8, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    731286c View commit details
Showing with 531 additions and 61 deletions.
  1. +1 −1 .release-please-manifest.json
  2. +8 −0 CHANGELOG.md
  3. +14 −14 README.md
  4. +1 −0 components/abstractions/android/build.gradle
  5. +3 −2 components/abstractions/gradle/dependencies.gradle
  6. +2 −4 components/abstractions/spotBugsExcludeFilter.xml
  7. +58 −0 components/abstractions/src/main/java/com/microsoft/kiota/serialization/KiotaJsonSerialization.java
  8. +86 −7 components/abstractions/src/main/java/com/microsoft/kiota/serialization/KiotaSerialization.java
  9. +69 −13 ...tractions/src/main/java/com/microsoft/kiota/serialization/SerializationWriterFactoryRegistry.java
  10. +4 −4 ...abstractions/src/main/java/com/microsoft/kiota/serialization/SerializationWriterProxyFactory.java
  11. +18 −0 ...ractions/src/main/java/com/microsoft/kiota/store/BackingStoreSerializationWriterProxyFactory.java
  12. +83 −0 ...onents/abstractions/src/test/java/com/microsoft/kiota/serialization/SerializationHelpersTest.java
  13. +168 −0 ...nts/abstractions/src/test/java/com/microsoft/kiota/serialization/mocks/TestBackedModelEntity.java
  14. +2 −2 components/authentication/azure/gradle/dependencies.gradle
  15. +2 −2 components/bundle/gradle/dependencies.gradle
  16. +2 −2 components/http/okHttp/gradle/dependencies.gradle
  17. +1 −1 ...http/okHttp/src/main/java/com/microsoft/kiota/http/middleware/options/UserAgentHandlerOption.java
  18. +2 −2 components/serialization/form/gradle/dependencies.gradle
  19. +2 −2 components/serialization/json/gradle/dependencies.gradle
  20. +1 −1 components/serialization/multipart/gradle/dependencies.gradle
  21. +2 −2 components/serialization/text/gradle/dependencies.gradle
  22. +2 −2 gradle.properties
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
@@ -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)


28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -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'
```
@@ -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>
1 change: 1 addition & 0 deletions components/abstractions/android/build.gradle
Original file line number Diff line number Diff line change
@@ -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 {
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'
6 changes: 2 additions & 4 deletions components/abstractions/spotBugsExcludeFilter.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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
@@ -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
Original file line number Diff line number Diff line change
@@ -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() {}

@@ -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();
}
@@ -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);
}
}
@@ -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();
}
@@ -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);
}

/**
Loading