private void addJsonTypeInfoAnnotation(JDefinedClass jclass, JsonNode node) { if (ruleFactory.getGenerationConfig().getAnnotationStyle() == AnnotationStyle.JACKSON2) { String annotationName = node.get("deserializationClassProperty").asText(); JAnnotationUse jsonTypeInfo = jclass.annotate(JsonTypeInfo.class); jsonTypeInfo.param("use", JsonTypeInfo.Id.CLASS); jsonTypeInfo.param("include", JsonTypeInfo.As.PROPERTY); jsonTypeInfo.param("property", annotationName); } }
@Override public void propertySetter(JMethod setter, JDefinedClass clazz, String propertyName) { setter.annotate(JsonProperty.class).param("value", propertyName); }
@Override public void propertySetter(JMethod setter, JDefinedClass clazz, String propertyName) { setter.annotate(JsonProperty.class).param("value", propertyName); }
@Override public void propertyInclusion(JDefinedClass clazz, JsonNode schema) { clazz.annotate(JsonInclude.class).param("value", inclusionLevel); }
@Override public void enumConstant(JDefinedClass _enum, JEnumConstant constant, String value) { constant.annotate(SerializedName.class).param("value", value); }
@Override public void propertyInclusion(JDefinedClass clazz, JsonNode schema) { clazz.annotate(JsonSerialize.class).param("include", inclusionLevel); }
@Override public void propertyGetter(JMethod getter, JDefinedClass clazz, String propertyName) { getter.annotate(JsonProperty.class).param("value", propertyName); }
@Override public void propertyGetter(JMethod getter, JDefinedClass clazz, String propertyName) { getter.annotate(JsonProperty.class).param("value", propertyName); }
@Override public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) { if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations() && (node.has("minLength") || node.has("maxLength"))) { JAnnotationUse annotation = field.annotate(Size.class); if (node.has("minLength")) { annotation.param("min", node.get("minLength").asInt()); } if (node.has("maxLength")) { annotation.param("max", node.get("maxLength").asInt()); } } return field; }
@Override public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) { if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations() && (node.has("minItems") || node.has("maxItems"))) { JAnnotationUse annotation = field.annotate(Size.class); if (node.has("minItems")) { annotation.param("min", node.get("minItems").asInt()); } if (node.has("maxItems")) { annotation.param("max", node.get("maxItems").asInt()); } } return field; }
@Override public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) { if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations()) { if (node.has("minimum")) { JAnnotationUse annotation = field.annotate(DecimalMin.class); annotation.param("value", node.get("minimum").asText()); } if (node.has("maximum")) { JAnnotationUse annotation = field.annotate(DecimalMax.class); annotation.param("value", node.get("maximum").asText()); } } return field; }
@Override public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) { field.annotate(SerializedName.class).param("value", propertyName); field.annotate(Expose.class); }
@Override public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) { field.annotate(JsonProperty.class).param("value", propertyName); if (field.type().erasure().equals(field.type().owner().ref(Set.class))) { field.annotate(JsonDeserialize.class).param("as", LinkedHashSet.class); } if (propertyNode.has("javaJsonView")) { field.annotate(JsonView.class).param( "value", field.type().owner().ref(propertyNode.get("javaJsonView").asText())); } if (propertyNode.has("description")) { field.annotate(JsonPropertyDescription.class).param("value", propertyNode.get("description").asText()); } }
@Override public void dateTimeField(JFieldVar field, JDefinedClass clazz, JsonNode node) { String timezone = node.has("customTimezone") ? node.get("customTimezone").asText() : "UTC"; String pattern = null; if (node.has("customDateTimePattern")) { pattern = node.get("customDateTimePattern").asText(); } else if (node.has("customPattern")) { pattern = node.get("customPattern").asText(); } else if (isNotEmpty(getGenerationConfig().getCustomDateTimePattern())) { pattern = getGenerationConfig().getCustomDateTimePattern(); } else if (getGenerationConfig().isFormatDateTimes()) { pattern = FormatRule.ISO_8601_DATETIME_FORMAT; } if (pattern != null && !field.type().fullName().equals("java.lang.String")) { field.annotate(JsonFormat.class).param("shape", JsonFormat.Shape.STRING).param("pattern", pattern).param("timezone", timezone); } } }
@Override public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) { if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations()) { JAnnotationUse annotation = field.annotate(Pattern.class); annotation.param("regexp", node.asText()); } return field; }
@Override public void dateField(JFieldVar field, JDefinedClass clazz, JsonNode node) { String pattern = null; if (node.has("customDatePattern")) { pattern = node.get("customDatePattern").asText(); } else if (node.has("customPattern")) { pattern = node.get("customPattern").asText(); } else if (isNotEmpty(getGenerationConfig().getCustomDatePattern())) { pattern = getGenerationConfig().getCustomDatePattern(); } else if (getGenerationConfig().isFormatDates()) { pattern = FormatRule.ISO_8601_DATE_FORMAT; } if (pattern != null && !field.type().fullName().equals("java.lang.String")) { field.annotate(JsonFormat.class).param("shape", JsonFormat.Shape.STRING).param("pattern", pattern); } }
@Override public void timeField(JFieldVar field, JDefinedClass clazz, JsonNode node) { String pattern = null; if (node.has("customTimePattern")) { pattern = node.get("customTimePattern").asText(); } else if (node.has("customPattern")) { pattern = node.get("customPattern").asText(); } else if (isNotEmpty(getGenerationConfig().getCustomTimePattern())) { pattern = getGenerationConfig().getCustomTimePattern(); } else if (getGenerationConfig().isFormatDates()) { pattern = FormatRule.ISO_8601_TIME_FORMAT; } if (pattern != null && !field.type().fullName().equals("java.lang.String")) { field.annotate(JsonFormat.class).param("shape", JsonFormat.Shape.STRING).param("pattern", pattern); } }
@Override public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) { field.annotate(JsonProperty.class).param("value", propertyName); if (field.type().erasure().equals(field.type().owner().ref(Set.class))) { field.annotate(JsonDeserialize.class).param("as", LinkedHashSet.class); } if (propertyNode.has("javaJsonView")) { field.annotate(JsonView.class).param( "value", field.type().owner().ref(propertyNode.get("javaJsonView").asText())); } }
@Override public void propertyField(JFieldVar field, JDefinedClass clazz, String propertyName, JsonNode propertyNode) { JClass moshiAnnotation = clazz.owner().directClass("com.squareup.moshi.Json"); field.annotate(moshiAnnotation).param("name", propertyName); }
@Override public void enumConstant(JDefinedClass _enum, JEnumConstant constant, String value) { JClass moshiAnnotation = _enum.owner().directClass("com.squareup.moshi.Json"); constant.annotate(moshiAnnotation).param("name", value); }