io.vertx.codegen.type.MapperInfo Java Examples
The following examples show how to use
io.vertx.codegen.type.MapperInfo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RowMapperGen.java From vertx-sql-client with Apache License 2.0 | 6 votes |
private static String wrapExpr(TypeInfo type, String expr) { DataObjectInfo dataObject = type.getDataObject(); if (dataObject != null) { MapperInfo deserializer = dataObject.getDeserializer(); if (deserializer != null) { if (deserializer.getKind() == MapperKind.SELF) { return "new " + type.getName() + "(" + expr + ")"; } else { return deserializer.getQualifiedName() + "." + String.join(".", deserializer .getSelectors()) + "(" + expr + ")"; } } throw new UnsupportedOperationException(); } else { return expr; } }
Example #2
Source File: GeneratorUtils.java From vertx-service-proxy with Apache License 2.0 | 6 votes |
public static String generateDeserializeDataObject(String stmt, ClassTypeInfo doTypeInfo) { MapperInfo deserializer = doTypeInfo.getDataObject().getDeserializer(); String s; switch (deserializer.getKind()) { case SELF: s = String.format("new %s((%s)%s)", doTypeInfo.getName(), doTypeInfo.getDataObject().getJsonType().getSimpleName(), stmt); break; case STATIC_METHOD: StringBuilder sb = new StringBuilder(deserializer.getQualifiedName()); deserializer.getSelectors().forEach(selector -> { sb.append('.').append(selector); }); sb.append("((").append(deserializer.getJsonType().getSimpleName()).append(')').append(stmt).append(')'); s = sb.toString(); break; default: throw new AssertionError(); } return String.format("%s != null ? %s : null", stmt, s); }
Example #3
Source File: GeneratorUtils.java From vertx-service-proxy with Apache License 2.0 | 6 votes |
public static String generateSerializeDataObject(String stmt, ClassTypeInfo doTypeInfo) { MapperInfo serializer = doTypeInfo.getDataObject().getSerializer(); StringBuilder sb = new StringBuilder(); serializer.getSelectors().forEach(selector -> { sb.append('.').append(selector); }); String s; switch (serializer.getKind()) { case SELF: s = stmt + sb + "()"; break; case STATIC_METHOD: s = serializer.getQualifiedName() + sb + "(" + stmt + ")"; break; default: throw new AssertionError(); } return String.format("%s != null ? %s : null", stmt, s); }
Example #4
Source File: DataObjectHelperGen.java From vertx-codegen with Apache License 2.0 | 4 votes |
private void genToJson(String visibility, boolean inheritConverter, DataObjectModel model, PrintWriter writer) { String simpleName = model.getType().getSimpleName(); writer.print(" " + visibility + " static void toJson(" + simpleName + " obj, JsonObject json) {\n"); writer.print(" toJson(obj, json.getMap());\n"); writer.print(" }\n"); writer.print("\n"); writer.print(" " + visibility + " static void toJson(" + simpleName + " obj, java.util.Map<String, Object> json) {\n"); model.getPropertyMap().values().forEach(prop -> { if ((prop.isDeclared() || inheritConverter) && prop.getGetterMethod() != null && prop.isJsonifiable()) { ClassKind propKind = prop.getType().getKind(); if (propKind.basic) { if (propKind == ClassKind.STRING) { genPropToJson("", "", prop, writer); } else { switch (prop.getType().getSimpleName()) { case "char": case "Character": genPropToJson("Character.toString(", ")", prop, writer); break; default: genPropToJson("", "", prop, writer); } } } else { DataObjectInfo dataObject = prop.getType().getDataObject(); if (dataObject != null) { if (dataObject.isSerializable()) { String m; MapperInfo mapperInfo = dataObject.getSerializer(); String match; switch (mapperInfo.getKind()) { case SELF: m = ""; match = "." + String.join(".", mapperInfo.getSelectors()) + "()"; break; case STATIC_METHOD: m = mapperInfo.getQualifiedName() + "." + String.join(".", mapperInfo.getSelectors()) + "("; match = ")"; break; default: throw new UnsupportedOperationException(); } genPropToJson(m, match, prop, writer); } else { return; } } else { switch (propKind) { case API: if (prop.getType().getName().equals("io.vertx.core.buffer.Buffer")) { genPropToJson("java.util.Base64.getEncoder().encodeToString(", ".getBytes())", prop, writer); } break; case ENUM: genPropToJson("", ".name()", prop, writer); break; case JSON_OBJECT: case JSON_ARRAY: case OBJECT: genPropToJson("", "", prop, writer); break; case OTHER: if (prop.getType().getName().equals(Instant.class.getName())) { genPropToJson("DateTimeFormatter.ISO_INSTANT.format(", ")", prop, writer); } break; } } } } }); writer.print(" }\n"); }