Skip to content

Commit

Permalink
Update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Sep 21, 2024
1 parent 918092c commit b45de4f
Show file tree
Hide file tree
Showing 52 changed files with 431 additions and 269 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 @@ -122,6 +122,9 @@ public Example deserialize(JsonParser jp, DeserializationContext ctxt) throws IO
ret.setActualInstance(deserialized);
return ret;
}
if (tree.isEmpty()) {
return new Example();
}
throw new IOException(String.format("Failed deserialization for Example: %d classes match result, expected 1", match));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ public Example deserialize(JsonParser jp, DeserializationContext ctxt) throws IO
ret.setActualInstance(deserialized);
return ret;
}
if (tree.isEmpty()) {
return new Example();
}
throw new IOException(String.format("Failed deserialization for Example: %d classes match result, expected 1", match));
}

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 @@ -131,6 +131,9 @@ public Fruit deserialize(JsonParser jp, DeserializationContext ctxt) throws IOEx
ret.setActualInstance(deserialized);
return ret;
}
if (tree.isEmpty()) {
return new Fruit();
}
throw new IOException(String.format("Failed deserialization for Fruit: %d classes match result, expected 1", match));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ public FruitReq deserialize(JsonParser jp, DeserializationContext ctxt) throws I
ret.setActualInstance(deserialized);
return ret;
}
if (tree.isEmpty()) {
return new FruitReq();
}
throw new IOException(String.format("Failed deserialization for FruitReq: %d classes match result, expected 1", match));
}

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,50 @@ 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"));
if (tree.isEmpty()) {
return new GmFruit();
}
throw new IOException(String.format("Failed deserialization for GmFruit: %d classes match result, expected 1", match));
}

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

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

Expand Down Expand Up @@ -188,23 +211,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
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ public Mammal deserialize(JsonParser jp, DeserializationContext ctxt) throws IOE
ret.setActualInstance(deserialized);
return ret;
}
if (tree.isEmpty()) {
return new Mammal();
}
throw new IOException(String.format("Failed deserialization for Mammal: %d classes match result, expected 1", match));
}

Expand Down
Loading

0 comments on commit b45de4f

Please sign in to comment.