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

Support for Json (de)serialization #35

Merged
merged 82 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
72e3405
json Initial commit
Kees-Schotanus Aug 21, 2024
e936df4
json childNode enum duration support
Kees-Schotanus Aug 22, 2024
ff12902
json Added support for Duartion and DateTime
Kees-Schotanus Aug 23, 2024
21e05e3
json getCollectionOfPrimitiveValues naive implementation
Kees-Schotanus Aug 26, 2024
d93ef02
json First two unit tests work
Kees-Schotanus Aug 27, 2024
a57d00a
Changed baseUrl to baseurl
Kees-Schotanus Sep 17, 2024
b04a39e
Use correct contenttype
joanne-ter-maat Sep 17, 2024
f1b3546
Added generics to requestconfiguration
joanne-ter-maat Sep 18, 2024
6e43b5a
Additional functions for configure method
joanne-ter-maat Sep 18, 2024
e16651e
remove parameters here
joanne-ter-maat Sep 19, 2024
9697338
Use less parameters for method
joanne-ter-maat Sep 19, 2024
b0f45c0
Merge pull request #34 from ricardoboss/configuration_generics
joanne-ter-maat Sep 19, 2024
23b8f15
Not ignoring the version.dart file anymore
Kees-Schotanus Sep 20, 2024
19e8411
Corrected ignoring gen folder
Kees-Schotanus Sep 20, 2024
e7d0d0b
Copied version.dart since I could not get it to work
Kees-Schotanus Sep 20, 2024
76102a3
Still trying to get a version.dart
Kees-Schotanus Sep 20, 2024
4b09f13
Looks like it works with the xorrect version.dart file now.
Kees-Schotanus Sep 20, 2024
371c950
Reverting changes
Kees-Schotanus Sep 20, 2024
cbc8d3f
Implement getCollectionOfObjectValues and getCollectionOfEnumValues
joanne-ter-maat Sep 24, 2024
e885bbd
Fixed implementation of collection methods
joanne-ter-maat Sep 24, 2024
7028c85
Parse enum value as string
joanne-ter-maat Sep 24, 2024
f6c5d1f
Used proper name for factory
Kees-Schotanus Sep 24, 2024
6c1058d
Merge branch 'json' of github.com:ricardoboss/dart_kiota into json
Kees-Schotanus Sep 24, 2024
79122e0
Don't create copy of ApiException to throw, because then all values i…
joanne-ter-maat Sep 25, 2024
dec541d
Merge branch 'json' of github.com:ricardoboss/dart_kiota into json
Kees-Schotanus Sep 26, 2024
cd3b5d1
Get correct writer for corrected content type
joanne-ter-maat Sep 27, 2024
5df9b84
Initial commit for processing untyped data
Kees-Schotanus Sep 27, 2024
6cd2d1b
Merge branch 'json' of github.com:ricardoboss/dart_kiota into json
Kees-Schotanus Sep 27, 2024
69aae59
Start with json serialization
joanne-ter-maat Sep 27, 2024
94106c7
Fix entry mssing from originalKeys
joanne-ter-maat Oct 1, 2024
2d0cb4a
Small improvements in json serialization
joanne-ter-maat Oct 1, 2024
512baf8
Add to correct variable
joanne-ter-maat Oct 1, 2024
f40cfbf
more small improvements to json serialization
joanne-ter-maat Oct 1, 2024
a2b51e2
Added some json serialization tests
joanne-ter-maat Oct 1, 2024
6a87d64
Implemented other collection methods
joanne-ter-maat Oct 1, 2024
b7cd057
Serialize additional data, added test for object serialization
joanne-ter-maat Oct 1, 2024
944bfc9
Added some more tests for json serialization
joanne-ter-maat Oct 2, 2024
9f417ea
Some small improvements and added test for enum deserialization
joanne-ter-maat Oct 2, 2024
3a6b176
added calls to onBefore/Start/AfterObjectSerialization
joanne-ter-maat Oct 2, 2024
688567c
Fix readme mistakes
joanne-ter-maat Oct 2, 2024
061636c
Added testcases for issues found
joanne-ter-maat Oct 8, 2024
ac2c00b
don't use late
joanne-ter-maat Oct 9, 2024
c31b5e7
Revert "Don't create copy of ApiException to throw, because then all …
joanne-ter-maat Oct 9, 2024
f1fe240
Remove generated file
joanne-ter-maat Oct 9, 2024
1b10f40
Return node directly for simple types
joanne-ter-maat Oct 10, 2024
c11fc40
Make constructor const
joanne-ter-maat Oct 10, 2024
7a525f6
don't need named argument
joanne-ter-maat Oct 10, 2024
08a7d7d
Don't write everything as string
joanne-ter-maat Oct 10, 2024
56b6046
cast node directly
joanne-ter-maat Oct 10, 2024
5e3d016
Added suggested changes to parsenode
joanne-ter-maat Oct 10, 2024
29d62c7
Added test for intersection types with some small fixes
joanne-ter-maat Oct 16, 2024
9054909
also write additional values when writing object
joanne-ter-maat Oct 16, 2024
4b55c7b
Added tests for union type
joanne-ter-maat Oct 16, 2024
c7a44b5
Merge branch 'main' into json
joanne-ter-maat Oct 16, 2024
fed0c38
Merge branch 'main' into json
joanne-ter-maat Oct 18, 2024
8ec8322
Added tests for json factories, some formatting
joanne-ter-maat Oct 18, 2024
9c38dd5
Remove settings file
joanne-ter-maat Oct 18, 2024
b14f170
Initial commit
Kees-Schotanus Oct 23, 2024
b258d2b
Merge branch 'json' into multipart
Kees-Schotanus Oct 23, 2024
54f6825
Fixed writing a null value for additonal data.
Kees-Schotanus Oct 23, 2024
022bcc2
Multipart now has a working unit test.
Kees-Schotanus Oct 23, 2024
9510537
Made all untyped_... constructors const
Kees-Schotanus Oct 23, 2024
b0be359
Temporary fix to have a hard coded version number
Kees-Schotanus Oct 24, 2024
51bead9
Temporary fix to have a hard coded version number
Kees-Schotanus Oct 24, 2024
6ebe465
Merge branch 'json' of https://github.com/kiota-community/dart_kiota …
Kees-Schotanus Oct 25, 2024
5270a7c
Resolved compiler warings and formatted the code.
Kees-Schotanus Oct 28, 2024
ea03d29
Added entries for json to codeowners and makefile
joanne-ter-maat Nov 12, 2024
f955cdc
Simpler solution for json serialization writer
joanne-ter-maat Nov 12, 2024
72a7b14
Merge branch 'main' into json
joanne-ter-maat Nov 13, 2024
9acf83e
process untyped nodes in the serialization writer
joanne-ter-maat Nov 13, 2024
f7384ea
Merge branch 'main' into json
joanne-ter-maat Nov 13, 2024
50d70df
Merge branch 'json' into multipart
Kees-Schotanus Nov 13, 2024
bf7e305
Added myself to CODEOWNERS as requested by Ricardo
Kees-Schotanus Nov 13, 2024
cd2d835
Merge pull request #41 from kiota-community/multipart
Kees-Schotanus Nov 13, 2024
09cff4f
Added type to variable
joanne-ter-maat Nov 13, 2024
7370049
Not all datatypes are directly usable in jsonEncode, correct for this…
joanne-ter-maat Nov 14, 2024
90de047
Enhance writeObjectValue
Kees-Schotanus Nov 14, 2024
52d26a8
Fixed cosmetic changes noted by analyzer
Kees-Schotanus Nov 14, 2024
77f2489
Formatting
joanne-ter-maat Nov 14, 2024
e8f74f4
Added multipart serialization to makefile
Kees-Schotanus Nov 15, 2024
283ea4b
Fixed warnings
joanne-ter-maat Nov 15, 2024
ff84985
Solved merge conflicts
Kees-Schotanus Nov 18, 2024
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
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
* @ricardoboss
/packages/kiota_serialization_json @joanne-ter-maat
/packages/kiota_serialization_multipart @Kees-Schotanus
24 changes: 21 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub-get: pub-get-abstractions pub-get-http pub-get-serialization-text pub-get-serialization-form
pub-get: pub-get-abstractions pub-get-http pub-get-serialization-text pub-get-serialization-form pub-get-serialization-json pub-get-serialization-multipart

pub-get-abstractions:
cd packages/kiota_abstractions && dart pub get
Expand All @@ -12,10 +12,16 @@ pub-get-serialization-text:
pub-get-serialization-form:
cd packages/kiota_serialization_form && dart pub get

pub-get-serialization-json:
cd packages/kiota_serialization_json && dart pub get

pub-get-serialization-multipart:
cd packages/kiota_serialization_multipart && dart pub get

format:
dart format packages

generate: generate-abstractions generate-http generate-serialization-form
generate: generate-abstractions generate-http generate-serialization-form generate-serialization-json

generate-abstractions:
cd packages/kiota_abstractions && dart run build_runner build --delete-conflicting-outputs
Expand All @@ -26,7 +32,13 @@ generate-http:
generate-serialization-form:
cd packages/kiota_serialization_form && dart run build_runner build --delete-conflicting-outputs

test: test-abstractions test-http test-serialization-text test-serialization-form
generate-serialization-json:
cd packages/kiota_serialization_json && dart run build_runner build --delete-conflicting-outputs

generate-serialization-multipart:
cd packages/kiota_serialization_multipart && dart run build_runner build --delete-conflicting-outputs

test: test-abstractions test-http test-serialization-text test-serialization-form test-serialization-json test-serialization-multipart

test-abstractions: pub-get-abstractions generate-abstractions
cd packages/kiota_abstractions && dart test
Expand All @@ -39,3 +51,9 @@ test-serialization-text: pub-get-serialization-text

test-serialization-form: pub-get-serialization-form generate-serialization-form
cd packages/kiota_serialization_form && dart test

test-serialization-json: pub-get-serialization-json generate-serialization-json
cd packages/kiota_serialization_json && dart test

test-serialization-multipart: pub-get-serialization-multipart generate-serialization-multipart
cd packages/kiota_serialization_multipart && dart test
8 changes: 8 additions & 0 deletions packages/kiota_abstractions/lib/kiota_abstractions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ part 'src/serialization/serialization_writer.dart';
part 'src/serialization/serialization_writer_factory.dart';
part 'src/serialization/serialization_writer_factory_registry.dart';
part 'src/serialization/serialization_writer_proxy_factory.dart';
part 'src/serialization/untyped_array.dart';
part 'src/serialization/untyped_boolean.dart';
part 'src/serialization/untyped_double.dart';
part 'src/serialization/untyped_integer.dart';
part 'src/serialization/untyped_node.dart';
part 'src/serialization/untyped_null.dart';
part 'src/serialization/untyped_object.dart';
part 'src/serialization/untyped_string.dart';
part 'src/store/backed_model.dart';
part 'src/store/backing_store.dart';
part 'src/store/backing_store_factory.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ part of '../../kiota_abstractions.dart';

/// Defines a contract for models that can hold additional data besides the
/// properties defined in the model.
abstract class AdditionDataHolder {
abstract class AdditionalDataHolder {
/// Additional data that is not part of the model's properties.
Map<String, Object> additionalData = {};
Map<String, Object?> additionalData = {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ abstract class SerializationWriter {
void writeObjectValue<T extends Parsable>(
String? key,
T? value, [
Iterable<Parsable>? additionalValuesToMerge,
Iterable<Parsable?>? additionalValuesToMerge,
]);

/// Writes the specified enum value to the buffer with an optional given
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
part of '../../kiota_abstractions.dart';

/// Represents an untyped node with a collection of other untyped nodes.
class UntypedArray extends UntypedNode {
/// Constructs an instance from the supplied [collection]
const UntypedArray(this.collection);

final Iterable<UntypedNode> collection;

@override
Iterable<UntypedNode> getValue() {
return collection;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
part of '../../kiota_abstractions.dart';

class UntypedBoolean extends UntypedNode {
const UntypedBoolean({required this.value});

final bool value;

@override
bool? getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
part of '../../kiota_abstractions.dart';

class UntypedDouble extends UntypedNode {
const UntypedDouble(this.value);

final double value;

@override
double? getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
part of '../../kiota_abstractions.dart';

class UntypedInteger extends UntypedNode {
const UntypedInteger(this.value);

final int value;

@override
int? getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
part of '../../kiota_abstractions.dart';

/// Base class for untyped node.
class UntypedNode implements Parsable {
const UntypedNode();

/// Creates a new [UntypedNode] instance.
factory UntypedNode.createFromDiscriminatorValue(ParseNode _) {
return const UntypedNode();
}

/// The deserialization information for the current model.
/// Returns a map of serializer methods for this object.
@override
Map<String, void Function(ParseNode)> getFieldDeserializers() {
return {};
}

/// Serializes the current object
@override
void serialize(SerializationWriter writer) {
// no properties to serialize. This is handled by custom serialization logic.
}

/// Gets the value assigned to untyped node.
Object? getValue() {
throw Exception('getValue is implemented for derived types of UntypedNode');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
part of '../../kiota_abstractions.dart';

class UntypedNull extends UntypedNode {
const UntypedNull();

@override
Object? getValue() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
part of '../../kiota_abstractions.dart';

/// Represents an untyped node with object value.
class UntypedObject extends UntypedNode {
const UntypedObject(this.properties);

final Map<String, UntypedNode> properties;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
part of '../../kiota_abstractions.dart';

class UntypedString extends UntypedNode {
const UntypedString(this.value);

final String value;
ricardoboss marked this conversation as resolved.
Show resolved Hide resolved

@override
String? getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class HttpClientRequestAdapter implements RequestAdapter {
}

void _setBaseUrl(RequestInformation requestInfo) {
requestInfo.pathParameters['baseUrl'] = baseUrl;
requestInfo.pathParameters['baseurl'] = baseUrl;
ricardoboss marked this conversation as resolved.
Show resolved Hide resolved
}

ResponseHandler? _getResponseHandler(RequestInformation requestInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class FormParseNode implements ParseNode {
}

Map<String, Object>? additionalData;
if (item case final AdditionDataHolder dataHolder) {
if (item case final AdditionalDataHolder dataHolder) {
dataHolder.additionalData = additionalData ??= {};
}

Expand Down
ricardoboss marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class FormSerializationWriter implements SerializationWriter {
void writeObjectValue<T extends Parsable>(
String? key,
T? value, [
Iterable<Parsable>? additionalValuesToMerge,
Iterable<Parsable?>? additionalValuesToMerge,
]) {
if (writingObject) {
throw UnsupportedError(
Expand All @@ -168,12 +168,14 @@ class FormSerializationWriter implements SerializationWriter {

if (additionalValuesToMerge != null) {
for (final additionalValue in additionalValuesToMerge) {
onBeforeObjectSerialization?.call(additionalValue);
onStartObjectSerialization?.call(additionalValue, this);
if (additionalValue != null) {
onBeforeObjectSerialization?.call(additionalValue);
onStartObjectSerialization?.call(additionalValue, this);

additionalValue.serialize(this);
additionalValue.serialize(this);

onAfterObjectSerialization?.call(additionalValue);
onAfterObjectSerialization?.call(additionalValue);
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions packages/kiota_serialization_json/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock
4 changes: 4 additions & 0 deletions packages/kiota_serialization_json/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Unreleased

- Initial version.
- Provides parsing and serialization support for the `application/json` content type.
21 changes: 21 additions & 0 deletions packages/kiota_serialization_json/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The `kiota_serialization_json` package is the Dart Json serialization library implementation to
handle `application/json` responses.

## Usage

Install the package in the generated project:

> For now, you can add the git repository as a dependency in your `pubspec.yaml` file:
>
> ```yaml
> dependencies:
> kiota_serialization_json:
> git:
> url: https://github.com/ricardoboss/dart_kiota.git
> ref: main
> path: packages/kiota_serialization_json
> ```

```bash
dart pub add kiota_serialization_json
```
1 change: 1 addition & 0 deletions packages/kiota_serialization_json/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:strict/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// This library implements deserialization for application/json responses.
///
/// This library is not meant to be used directly, but rather to be used as a
/// dependency in the generated code.
library kiota_serialization_json;

import 'dart:convert';
import 'dart:typed_data';

import 'package:kiota_abstractions/kiota_abstractions.dart';
import 'package:uuid/uuid_value.dart';

part 'src/json_parse_node.dart';
part 'src/json_parse_node_factory.dart';
part 'src/json_serialization_writer.dart';
part 'src/json_serialization_writer_factory.dart';
Loading
Loading