Skip to content

Commit

Permalink
Update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Aug 24, 2024
1 parent 4767cb6 commit b41e61c
Show file tree
Hide file tree
Showing 29 changed files with 234 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{{#withXml}}
@XmlEnumValue({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
{{/withXml}}
{{{name}}}({{^isUri}}{{dataType}}.valueOf({{/isUri}}{{{value}}}{{^isUri}}){{/isUri}}){{^-last}},
{{{name}}}({{^isUri}}{{^isString}}{{dataType}}.valueOf({{/isString}}{{/isUri}}{{{value}}}{{^isUri}}{{^isString}}){{/isString}}{{/isUri}}){{^-last}},
{{/-last}}{{#-last}};{{/-last}}
{{/enumVars}}
{{/allowableValues}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ public static EnumStringRequiredEnum fromValue(String value) {
* Gets or Sets enumInteger
*/
public enum EnumIntegerEnum {
NUMBER_1(1),
NUMBER_1(Integer.valueOf(1)),

NUMBER_MINUS_1(-1);
NUMBER_MINUS_1(Integer.valueOf(-1));

private Integer value;

Expand Down Expand Up @@ -172,9 +172,9 @@ public static EnumIntegerEnum fromValue(Integer value) {
* Gets or Sets enumNumber
*/
public enum EnumNumberEnum {
NUMBER_1_DOT_1(1.1),
NUMBER_1_DOT_1(Double.valueOf(1.1)),

NUMBER_MINUS_1_DOT_2(-1.2);
NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));

private Double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ public static EnumStringRequiredEnum fromValue(String value) {
* Gets or Sets enumInteger
*/
public enum EnumIntegerEnum {
NUMBER_1(1),
NUMBER_1(Integer.valueOf(1)),

NUMBER_MINUS_1(-1);
NUMBER_MINUS_1(Integer.valueOf(-1));

private Integer value;

Expand Down Expand Up @@ -160,9 +160,9 @@ public static EnumIntegerEnum fromValue(Integer value) {
* Gets or Sets enumNumber
*/
public enum EnumNumberEnum {
NUMBER_1_DOT_1(1.1),
NUMBER_1_DOT_1(Double.valueOf(1.1)),

NUMBER_MINUS_1_DOT_2(-1.2);
NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));

private Double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ public static EnumStringRequiredEnum fromValue(String value) {
* Gets or Sets enumInteger
*/
public enum EnumIntegerEnum {
NUMBER_1(1),
NUMBER_1(Integer.valueOf(1)),

NUMBER_MINUS_1(-1);
NUMBER_MINUS_1(Integer.valueOf(-1));

private Integer value;

Expand Down Expand Up @@ -169,9 +169,9 @@ public static EnumIntegerEnum fromValue(Integer value) {
* Gets or Sets enumNumber
*/
public enum EnumNumberEnum {
NUMBER_1_DOT_1(1.1),
NUMBER_1_DOT_1(Double.valueOf(1.1)),

NUMBER_MINUS_1_DOT_2(-1.2);
NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));

private Double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ public static EnumStringRequiredEnum fromValue(String value) {
* Gets or Sets enumInteger
*/
public enum EnumIntegerEnum {
NUMBER_1(1),
NUMBER_1(Integer.valueOf(1)),

NUMBER_MINUS_1(-1);
NUMBER_MINUS_1(Integer.valueOf(-1));

private Integer value;

Expand Down Expand Up @@ -159,9 +159,9 @@ public static EnumIntegerEnum fromValue(Integer value) {
* Gets or Sets enumNumber
*/
public enum EnumNumberEnum {
NUMBER_1_DOT_1(1.1),
NUMBER_1_DOT_1(Double.valueOf(1.1)),

NUMBER_MINUS_1_DOT_2(-1.2);
NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));

private Double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ public static EnumStringRequiredEnum fromValue(String value) {
* Gets or Sets enumInteger
*/
public enum EnumIntegerEnum {
NUMBER_1(1),
NUMBER_1(Integer.valueOf(1)),

NUMBER_MINUS_1(-1);
NUMBER_MINUS_1(Integer.valueOf(-1));

private Integer value;

Expand Down Expand Up @@ -162,9 +162,9 @@ public static EnumIntegerEnum fromValue(Integer value) {
* Gets or Sets enumNumber
*/
public enum EnumNumberEnum {
NUMBER_1_DOT_1(1.1),
NUMBER_1_DOT_1(Double.valueOf(1.1)),

NUMBER_MINUS_1_DOT_2(-1.2);
NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));

private Double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ public static EnumStringRequiredEnum fromValue(String value) {
* Gets or Sets enumInteger
*/
public enum EnumIntegerEnum {
NUMBER_1(1),
NUMBER_1(Integer.valueOf(1)),

NUMBER_MINUS_1(-1);
NUMBER_MINUS_1(Integer.valueOf(-1));

private Integer value;

Expand Down Expand Up @@ -162,9 +162,9 @@ public static EnumIntegerEnum fromValue(Integer value) {
* Gets or Sets enumNumber
*/
public enum EnumNumberEnum {
NUMBER_1_DOT_1(1.1),
NUMBER_1_DOT_1(Double.valueOf(1.1)),

NUMBER_MINUS_1_DOT_2(-1.2);
NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));

private Double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ public static EnumStringRequiredEnum fromValue(String value) {
* Gets or Sets enumInteger
*/
public enum EnumIntegerEnum {
NUMBER_1(1),
NUMBER_1(Integer.valueOf(1)),

NUMBER_MINUS_1(-1);
NUMBER_MINUS_1(Integer.valueOf(-1));

private Integer value;

Expand Down Expand Up @@ -175,9 +175,9 @@ public static EnumIntegerEnum fromValue(Integer value) {
* Gets or Sets enumIntegerOnly
*/
public enum EnumIntegerOnlyEnum {
NUMBER_2(2),
NUMBER_2(Integer.valueOf(2)),

NUMBER_MINUS_2(-2);
NUMBER_MINUS_2(Integer.valueOf(-2));

private Integer value;

Expand Down Expand Up @@ -213,9 +213,9 @@ public static EnumIntegerOnlyEnum fromValue(Integer value) {
* Gets or Sets enumNumber
*/
public enum EnumNumberEnum {
NUMBER_1_DOT_1(1.1),
NUMBER_1_DOT_1(Double.valueOf(1.1)),

NUMBER_MINUS_1_DOT_2(-1.2);
NUMBER_MINUS_1_DOT_2(Double.valueOf(-1.2));

private Double value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
Expand Down Expand Up @@ -89,29 +91,47 @@ public GmFruit deserialize(JsonParser jp, DeserializationContext ctxt) throws IO
JsonNode tree = jp.readValueAsTree();

Object deserialized = null;
// deserialize Apple
boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS);
int match = 0;
JsonToken token = tree.traverse(jp.getCodec()).nextToken();
// deserialize Apple (nullable)
try {
deserialized = tree.traverse(jp.getCodec()).readValueAs(Apple.class);
GmFruit ret = new GmFruit();
ret.setActualInstance(deserialized);
return ret;
boolean attemptParsing = true;
if (attemptParsing) {
deserialized = tree.traverse(jp.getCodec()).readValueAs(Apple.class);
// TODO: there is no validation against JSON schema constraints
// (min, max, enum, pattern...), this does not perform a strict JSON
// validation, which means the 'match' count may be higher than it should be.
match++;
log.log(Level.FINER, "Input data matches schema 'Apple'");
}
} catch (Exception e) {
// deserialization failed, continue, log to help debugging
log.log(Level.FINER, "Input data does not match 'GmFruit'", e);
// deserialization failed, continue
log.log(Level.FINER, "Input data does not match schema 'Apple'", e);
}

// deserialize Banana
try {
deserialized = tree.traverse(jp.getCodec()).readValueAs(Banana.class);
boolean attemptParsing = true;
if (attemptParsing) {
deserialized = tree.traverse(jp.getCodec()).readValueAs(Banana.class);
// TODO: there is no validation against JSON schema constraints
// (min, max, enum, pattern...), this does not perform a strict JSON
// validation, which means the 'match' count may be higher than it should be.
match++;
log.log(Level.FINER, "Input data matches schema 'Banana'");
}
} catch (Exception e) {
// deserialization failed, continue
log.log(Level.FINER, "Input data does not match schema 'Banana'", e);
}

if (match == 1) {
GmFruit ret = new GmFruit();
ret.setActualInstance(deserialized);
return ret;
} catch (Exception e) {
// deserialization failed, continue, log to help debugging
log.log(Level.FINER, "Input data does not match 'GmFruit'", e);
}

throw new IOException(String.format("Failed deserialization for GmFruit: no match found"));
throw new IOException(String.format("Failed deserialization for GmFruit: %d classes match result, expected 1", match));
}

/**
Expand All @@ -131,7 +151,7 @@ public GmFruit() {
}

public GmFruit(Apple o) {
super("anyOf", Boolean.FALSE);
super("anyOf", Boolean.TRUE);
setActualInstance(o);
}

Expand Down Expand Up @@ -188,23 +208,23 @@ public Object getActualInstance() {
}

/**
* Get the actual instance of `Apple`. If the actual instance is not `Apple`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `Apple`
* @throws ClassCastException if the instance is not `Apple`
*/
* Get the actual instance of `Apple`. If the actual instance is not `Apple`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `Apple`
* @throws ClassCastException if the instance is not `Apple`
*/
public Apple getApple() throws ClassCastException {
return (Apple)super.getActualInstance();
}

/**
* Get the actual instance of `Banana`. If the actual instance is not `Banana`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `Banana`
* @throws ClassCastException if the instance is not `Banana`
*/
* Get the actual instance of `Banana`. If the actual instance is not `Banana`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `Banana`
* @throws ClassCastException if the instance is not `Banana`
*/
public Banana getBanana() throws ClassCastException {
return (Banana)super.getActualInstance();
}
Expand Down
Loading

0 comments on commit b41e61c

Please sign in to comment.