POJO to JSON schema

48 views
Skip to first unread message

rgoya...@gmail.com

unread,
Feb 4, 2016, 1:56:51 AM2/4/16
to jsonschema2pojo-users
Hi,

I have a use case where I want to convert existing java POJO to JSON schema which is then compatible with jsonschema2pojo. I have tried following methods - 


Using codehaus mapper

org.codehaus.jackson.map.ObjectMapper codehausMapper = new org.codehaus.jackson.map.ObjectMapper();
codehausMapper
.configure(SerializationConfig.Feature.WRITE_ENUMS_USING_TO_STRING, true);
org
.codehaus.jackson.schema.JsonSchema codehausSchema = codehausMapper.generateJsonSchema(SvcCompleteCartResponse.class);
System.out.println(
codehausMapper
.writeValueAsString(codehausSchema));

This one generates one big schema for given POJO and does not use referencing anywhere so my classes are not re-used when I convert schmea back to POJO using jsonschema2pojo

Using jackson-module-jsonSchema

ObjectMapper fxmlMapper = new ObjectMapper();
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
fxmlMapper.acceptJsonFormatVisitor(fxmlMapper.constructType(SvcCompleteCartResponse.class), visitor);
JsonSchema jsonSchema = visitor.finalSchema();

This one also generates one big schema and this schema is not even compatible with 
jsonschema2pojo


Is there any way of converting my existing POJOs to JSON schema which is compatible with jsonschema2pojo and have reference based schema so that my classes are re-usable ?


Reply all
Reply to author
Forward
0 new messages