Skip to content

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

Closed
@sushmayellampally

Description

@sushmayellampally

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"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions