Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonFormat not supported? #133

Open
dherges opened this issue Nov 9, 2018 · 1 comment
Open

JsonFormat not supported? #133

dherges opened this issue Nov 9, 2018 · 1 comment

Comments

@dherges
Copy link

dherges commented Nov 9, 2018

Entity:

public class Wound {

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss", timezone = "UTC")
    @JsonProperty("createdAt")
    @JsonPropertyDescription("A date time object w/o timezone.")
    @NotNull
    private LocalDateTime createdAt;

}

When I generate with JavaTimeModule(), I get an array of integer in the json schema:

        ObjectMapper objectMapper = new ObjectMapper();
                .registerModule(new JavaTimeModule());

        JsonSchemaGenerator jsonSchemaGenerator = new JsonSchemaGenerator(objectMapper);
        JsonNode jsonSchema = jsonSchemaGenerator.generateJsonSchema(Wound.class);
        String jsonSchemaAsString = objectMapper.writeValueAsString(jsonSchema);
        "createdAt": {
          "type": "array",
          "items": {
            "type": "integer"
          },
          "description": "A date time object w/o timezone."
        }

When I omit the JavaTimeModule, I a get a LocalDateTimeObject with Java members:

    "LocalDateTime": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "dayOfYear": {
          "type": "integer"
        },
        "dayOfWeek": {
          "type": "string",
          "enum": [
            "MONDAY",
            "TUESDAY",
            "WEDNESDAY",
            "THURSDAY",
            "FRIDAY",
            "SATURDAY",
            "SUNDAY"
          ]
        },
        "year": {
          "type": "integer"
        },
...

EXPECTED RESULT:

    "dateTime": {
      "description": "A date time object w/o timezone.",
      "type": "string",
      "format": "date-time",
      "javaType": "java.time.LocalDateTime",
      "customDateTimePattern" : "yyyy-MM-dd'T'HH:mm:ss"
    }
@bmogensen
Copy link

I am having the same issue. I am pretty new to the schema generation but have been trying to get java.util.Date to be formatted with this annotation:

	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss", timezone = "UTC")
	@JsonSchema(
			description = "When the contact address is valid from",
			required = true)
	private Date effectiveFrom;

Right now I am trying to use the addon module instead and then set it like this instead:

	@JsonSchema(
			description = "When the contact address is valid to",
			required = false,
			format=TypeFormat.DATE_TIME)
	private Date effectiveTo;

However I am not sure it solves your more advanced example :) and I am not sure if it will be strict enough for our schemas to be honest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants