Skip to content

Commit

Permalink
Use @JsonGen annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Nov 30, 2023
1 parent a3cf63f commit 8c43182
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class JsonSchemaOptionsConverter {
private static final Base64.Decoder BASE64_DECODER = JsonUtil.BASE64_DECODER;
private static final Base64.Encoder BASE64_ENCODER = JsonUtil.BASE64_ENCODER;

public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, JsonSchemaOptions obj) {
static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, JsonSchemaOptions obj) {
for (java.util.Map.Entry<String, Object> member : json) {
switch (member.getKey()) {
case "baseUri":
Expand All @@ -39,11 +39,11 @@ public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json,
}
}

public static void toJson(JsonSchemaOptions obj, JsonObject json) {
static void toJson(JsonSchemaOptions obj, JsonObject json) {
toJson(obj, json.getMap());
}

public static void toJson(JsonSchemaOptions obj, java.util.Map<String, Object> json) {
static void toJson(JsonSchemaOptions obj, java.util.Map<String, Object> json) {
if (obj.getBaseUri() != null) {
json.put("baseUri", obj.getBaseUri());
}
Expand Down
72 changes: 36 additions & 36 deletions src/main/generated/io/vertx/json/schema/OutputUnitConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,27 @@ public class OutputUnitConverter {
private static final Base64.Decoder BASE64_DECODER = JsonUtil.BASE64_DECODER;
private static final Base64.Encoder BASE64_ENCODER = JsonUtil.BASE64_ENCODER;

public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, OutputUnit obj) {
static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, OutputUnit obj) {
for (java.util.Map.Entry<String, Object> member : json) {
switch (member.getKey()) {
case "valid":
if (member.getValue() instanceof Boolean) {
obj.setValid((Boolean)member.getValue());
}
break;
case "absoluteKeywordLocation":
if (member.getValue() instanceof String) {
obj.setAbsoluteKeywordLocation((String)member.getValue());
}
break;
case "annotations":
if (member.getValue() instanceof JsonArray) {
java.util.ArrayList<io.vertx.json.schema.OutputUnit> list = new java.util.ArrayList<>();
((Iterable<Object>)member.getValue()).forEach( item -> {
if (item instanceof JsonObject)
list.add(new io.vertx.json.schema.OutputUnit((io.vertx.core.json.JsonObject)item));
});
obj.setAnnotations(list);
case "keywordLocation":
if (member.getValue() instanceof String) {
obj.setKeywordLocation((String)member.getValue());
}
break;
case "instanceLocation":
if (member.getValue() instanceof String) {
obj.setInstanceLocation((String)member.getValue());
}
break;
case "error":
Expand All @@ -50,37 +55,36 @@ public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json,
obj.setErrors(list);
}
break;
case "instanceLocation":
if (member.getValue() instanceof String) {
obj.setInstanceLocation((String)member.getValue());
}
break;
case "keywordLocation":
if (member.getValue() instanceof String) {
obj.setKeywordLocation((String)member.getValue());
}
break;
case "valid":
if (member.getValue() instanceof Boolean) {
obj.setValid((Boolean)member.getValue());
case "annotations":
if (member.getValue() instanceof JsonArray) {
java.util.ArrayList<io.vertx.json.schema.OutputUnit> list = new java.util.ArrayList<>();
((Iterable<Object>)member.getValue()).forEach( item -> {
if (item instanceof JsonObject)
list.add(new io.vertx.json.schema.OutputUnit((io.vertx.core.json.JsonObject)item));
});
obj.setAnnotations(list);
}
break;
}
}
}

public static void toJson(OutputUnit obj, JsonObject json) {
static void toJson(OutputUnit obj, JsonObject json) {
toJson(obj, json.getMap());
}

public static void toJson(OutputUnit obj, java.util.Map<String, Object> json) {
static void toJson(OutputUnit obj, java.util.Map<String, Object> json) {
if (obj.getValid() != null) {
json.put("valid", obj.getValid());
}
if (obj.getAbsoluteKeywordLocation() != null) {
json.put("absoluteKeywordLocation", obj.getAbsoluteKeywordLocation());
}
if (obj.getAnnotations() != null) {
JsonArray array = new JsonArray();
obj.getAnnotations().forEach(item -> array.add(item.toJson()));
json.put("annotations", array);
if (obj.getKeywordLocation() != null) {
json.put("keywordLocation", obj.getKeywordLocation());
}
if (obj.getInstanceLocation() != null) {
json.put("instanceLocation", obj.getInstanceLocation());
}
if (obj.getError() != null) {
json.put("error", obj.getError());
Expand All @@ -90,14 +94,10 @@ public static void toJson(OutputUnit obj, java.util.Map<String, Object> json) {
obj.getErrors().forEach(item -> array.add(item.toJson()));
json.put("errors", array);
}
if (obj.getInstanceLocation() != null) {
json.put("instanceLocation", obj.getInstanceLocation());
}
if (obj.getKeywordLocation() != null) {
json.put("keywordLocation", obj.getKeywordLocation());
}
if (obj.getValid() != null) {
json.put("valid", obj.getValid());
if (obj.getAnnotations() != null) {
JsonArray array = new JsonArray();
obj.getAnnotations().forEach(item -> array.add(item.toJson()));
json.put("annotations", array);
}
}
}
4 changes: 3 additions & 1 deletion src/main/java/io/vertx/json/schema/JsonSchemaOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package io.vertx.json.schema;

import io.vertx.codegen.annotations.DataObject;
import io.vertx.codegen.json.annotations.JsonGen;
import io.vertx.core.json.JsonObject;

import java.util.Objects;
Expand All @@ -20,7 +21,8 @@
*
* @author Paulo Lopes
*/
@DataObject(generateConverter = true)
@DataObject
@JsonGen(publicConverter = false)
public class JsonSchemaOptions {

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/vertx/json/schema/OutputUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@

import io.vertx.codegen.annotations.DataObject;
import io.vertx.codegen.annotations.GenIgnore;
import io.vertx.codegen.json.annotations.JsonGen;
import io.vertx.core.json.JsonObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@DataObject(generateConverter = true)
@DataObject
@JsonGen(publicConverter = false)
public class OutputUnit {

private Boolean valid;
Expand Down

0 comments on commit 8c43182

Please sign in to comment.