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

[Java] Untyped nodes #1070

Merged
merged 25 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d536772
WIP: Base models
Feb 1, 2024
d67e8ee
Merge remote-tracking branch 'origin/main' into andrueastman/untypedN…
Feb 2, 2024
65a1eb9
WIP: TODO test serialization
Feb 5, 2024
1d4d856
Merge remote-tracking branch 'origin/andrueastman/untypedNodes' into …
Feb 5, 2024
ff461ed
Merge remote-tracking branch 'origin/main' into andrueastman/untypedN…
Feb 5, 2024
823f268
Tests working. Todo cleanup and linting.
Feb 5, 2024
3b7697e
Cleanup
Feb 5, 2024
4075056
Merge remote-tracking branch 'origin/main' into andrueastman/untypedN…
Feb 5, 2024
3de7816
Adds cahngelog
Feb 5, 2024
83ff855
Fix annotations
Feb 6, 2024
aaab7d8
Merge remote-tracking branch 'origin/main' into andrueastman/untypedN…
Feb 6, 2024
7977a9f
Missing annotation
Feb 6, 2024
65089cc
format
Feb 6, 2024
4a53678
Merge remote-tracking branch 'origin/main' into andrueastman/untypedN…
Feb 8, 2024
1432cbb
Updates version and release notes.
Feb 8, 2024
4334677
Merge remote-tracking branch 'origin/main' into andrueastman/untypedN…
Feb 27, 2024
b1b8922
Merge branch 'andrueastman/untypedNodes' of https://github.com/micros…
Feb 27, 2024
7200636
Fix merge errors
Feb 27, 2024
58d4322
Fix changelog
Feb 27, 2024
5207ca4
Merge remote-tracking branch 'origin/main' into andrueastman/untypedN…
Mar 4, 2024
bf75056
Apply suggestions
Mar 4, 2024
5415535
Merge remote-tracking branch 'origin/main' into andrueastman/untypedN…
Mar 5, 2024
be64ce4
Fix changelog merge
Mar 5, 2024
f6c9315
consistency
Mar 7, 2024
326a9d4
Merge remote-tracking branch 'origin/main' into andrueastman/untypedN…
Mar 19, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [1.1.0] - 2024-02-14

### Added

- Adds support for untyped nodes.

## [1.0.6] - 2023-03-04

### Changed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.microsoft.kiota.serialization;

import jakarta.annotation.Nonnull;

/**
* Represents an untyped node with a collection of other untyped nodes.
*/
public class UntypedArray extends UntypedNode {
/**
* The constructor for the UntypedArray
* @param collection Collection to initialize with.
*/
public UntypedArray(@Nonnull Iterable<UntypedNode> collection) {
value = collection;
}

private final Iterable<UntypedNode> value;

/**
* Gets the value assigned to untyped node.
* @return The string value of the node.
*/
@Override
@Nonnull public Iterable<UntypedNode> getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.microsoft.kiota.serialization;

import jakarta.annotation.Nonnull;

/**
* Represents an untyped node with boolean value.
*/
public class UntypedBoolean extends UntypedNode {
/**
* The constructor for the UntypedBoolean
* @param boolValue Boolean to create node with.
*/
public UntypedBoolean(@Nonnull Boolean boolValue) {
value = boolValue;
}

private final Boolean value;

/**
* Gets the value assigned to untyped node.
* @return The bool value of the node.
*/
@Override
@Nonnull public Boolean getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.microsoft.kiota.serialization;

import jakarta.annotation.Nonnull;

import java.math.BigDecimal;

/**
* Represents an untyped node with decimal value.
*/
public class UntypedDecimal extends UntypedNode {
/**
* The constructor for the UntypedDecimal
* @param decimalValue The decimal to create the node with.
*/
public UntypedDecimal(@Nonnull BigDecimal decimalValue) {
value = decimalValue;
}

private final BigDecimal value;

/**
* Gets the value assigned to untyped node.
* @return The BigDecimal value of the node.
*/
@Override
@Nonnull public BigDecimal getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.microsoft.kiota.serialization;

import jakarta.annotation.Nonnull;

/**
* Represents an untyped node with double value.
*/
public class UntypedDouble extends UntypedNode {
/**
* The constructor for the UntypedDouble
* @param doubleValue The Double to create the node with.
*/
public UntypedDouble(@Nonnull Double doubleValue) {
value = doubleValue;
}

private final Double value;

/**
* Gets the value assigned to untyped node.
* @return The double value of the node.
*/
@Override
@Nonnull public Double getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.microsoft.kiota.serialization;

import jakarta.annotation.Nonnull;

/**
* Represents an untyped node with Float value.
*/
public class UntypedFloat extends UntypedNode {
/**
* The constructor for the UntypedFloat
* @param floatValue The float value to create the node with.
*/
public UntypedFloat(@Nonnull Float floatValue) {
value = floatValue;
}

private final Float value;

/**
* Gets the value assigned to untyped node.
* @return The float value of the node.
*/
@Override
@Nonnull public Float getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.microsoft.kiota.serialization;

import jakarta.annotation.Nonnull;

/**
* Represents an untyped node with integer value.
*/
public class UntypedInteger extends UntypedNode {
/**
* The constructor for the UntypedObject
* @param intValue The integer to create the node with.
*/
public UntypedInteger(@Nonnull Integer intValue) {
value = intValue;
}

private final Integer value;

/**
* Gets the value assigned to untyped node.
* @return The integer value of the node.
*/
@Override
@Nonnull public Integer getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.microsoft.kiota.serialization;

import jakarta.annotation.Nonnull;

/**
* Represents an untyped node with Long value.
*/
public class UntypedLong extends UntypedNode {
/**
* The constructor for the UntypedLong
* @param longValue The long value to create the node with.
*/
public UntypedLong(@Nonnull Long longValue) {
value = longValue;
}

private final Long value;

/**
* Gets the value assigned to untyped node.
* @return The long value of the node.
*/
@Override
@Nonnull public Long getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.microsoft.kiota.serialization;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

/**
* Base class for untyped node.
*/
public class UntypedNode implements Parsable {

/**
* The deserialization information for the current model.
* @return The map of serializer methods for this object.
*/
@Nonnull @Override
public Map<String, Consumer<ParseNode>> getFieldDeserializers() {
return new HashMap<>();
}

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

/**
* Gets the value assigned to untyped node.
* @return The value assigned to untyped node.
*/
@Nullable public Object getValue() {
throw new UnsupportedOperationException(
"getValue is implemented for derived types of UntypedNode");
}

/**
* Creates a new instance of the appropriate class based on discriminator value.
* @param parseNode The parse node to crate from
* @return A new UntypedNode instance.
*/
@Nonnull public static UntypedNode createFromDiscriminatorValue(@Nonnull final ParseNode parseNode) {
return new UntypedNode();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.microsoft.kiota.serialization;

import jakarta.annotation.Nullable;

/**
* Represents an untyped node with null value.
*/
public class UntypedNull extends UntypedNode {
/**
* The default constructor for the UntypedNull
*/
public UntypedNull() {
// empty constructor
}

/**
* Gets the value assigned to untyped node.
* @return null value.
*/
@Override
@Nullable public Object getValue() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.microsoft.kiota.serialization;

import jakarta.annotation.Nonnull;

import java.util.HashMap;
import java.util.Map;

/**
* Represents an untyped node with object value.
*/
public class UntypedObject extends UntypedNode {
/**
* The constructor for the UntypedObject
* @param propertiesMap The Map to create the node with
*/
public UntypedObject(@Nonnull Map<String, UntypedNode> propertiesMap) {
properties = new HashMap<>(propertiesMap);
}

private final Map<String, UntypedNode> properties;

/**
* Gets the value assigned to untyped node.
* @return The Map of property keys and their values.
*/
@Override
@Nonnull public Map<String, UntypedNode> getValue() {
return new HashMap<>(properties);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.microsoft.kiota.serialization;

import jakarta.annotation.Nonnull;

/**
* Represents an untyped node with string value.
*/
public class UntypedString extends UntypedNode {
/**
* The constructor for the UntypedObject
* @param stringValue The string to create the node with.
*/
public UntypedString(@Nonnull String stringValue) {
value = stringValue;
}

private final String value;

/**
* Gets the value assigned to untyped node.
* @return The string value of the node.
*/
@Override
@Nonnull public String getValue() {
return value;
}
}
1 change: 1 addition & 0 deletions components/serialization/json/spotBugsExcludeFilter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubu
<Class name="com.microsoft.kiota.serialization.mocks.UnionTypeMock" />
<Class name="com.microsoft.kiota.serialization.mocks.SecondTestEntity" />
<Class name="com.microsoft.kiota.serialization.mocks.TestEntity" />
<Class name="com.microsoft.kiota.serialization.mocks.UntypedTestEntity" />
</Or>
</Match>
<Match>
Expand Down
Loading
Loading