Skip to content

Using both JAXB and Jackson annotations to serialize/deserialize data #268

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

Closed
sushmayellampally opened this issue Jun 28, 2018 · 2 comments

Comments

@sushmayellampally
Copy link

sushmayellampally commented Jun 28, 2018

My POJO element is:

@XmlElement(name = "TrackDt", required = true)
@XmlSchemaType(name = "date")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "GMT")
protected XMLGregorianCalendar trackDt;

During generating Json schema, I am using both JAXB and Jackson annotaions by adding introspectors like below:

JacksonAnnotationIntrospector primary = new JacksonAnnotationIntrospector();
JaxbAnnotationIntrospector secondary = new 
JaxbAnnotationIntrospector(typeFactory);
mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(primary, secondary));

The generated Json schema looks like:

..
 "TrackDt": {
        "type": "string",
        "format": "date-time"
    }
..
"required": ["TrackDt"]

A Json request example:
{
....
"TrackDt": "2017-06-13",
....
}
While validating this JSON instance against the schema, the date is validated and the response contains the dates according to the pattern specified in @jsonformat annotation.

Now , I want to add JAXB annotation introspector and use JAXB annotations also. But the validator throws following error:

Exception while reading input message; nested exception is 
com.github.fge.jsonschema.core.exceptions.ProcessingException: fatal: string 
"2017-06-13" is invalid against requested date format(s) [yyyy-MM- 
dd'T'HH:mm:ssZ, yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,12}Z] level: "fatal" schema: 
{"loadingURI":"#","pointer":"../properties/TrackDt"} 
instance: {"pointer":"/TrackDt"} domain: "validation" keyword: "format" 
attribute: "date-time" value: "2017-06-13" expected: ["yyyy-MM- 
dd'T'HH:mm:ssZ","yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,12}Z"]
@sushmayellampally
Copy link
Author

Why would the validation fails if I add Jaxb annotation introspector?

@sushmayellampally
Copy link
Author

Closing this issue. This error is related to #103. Adding the date and time attributes fixed the error.

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

1 participant