I have a class:
class Setting {
String configurationName;
String configuration;
}
I want to return the string representation how configuration will look like. This can be different object based on some conditions.
In one of service I do below :
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getConfigurationSetting ()
{
try {
Setting settingPojo = new Setting();
settingPojo.setCOnfigurationName("DataBase");
ObjectMapper mapper = new ObjectMapper();
SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
mapper.acceptJsonFormatVisitor(OracleConfiguration.class, visitor);
JsonSchema schema = visitor.finalSchema();
settingPojo.setConfiguraton(mapper.writeValueAsString(schema));
return Response.status(HTTP.CodeOK).entity(settingPojo).build();
} catch (Exception ex) {
// exception logic
}
}
There can be different class like this : "MySQLConfiguration.class".
Sample :
{
configurationName : "DataBase",
configuration: "{
\"type\":\"object\",
\"id\":\"urn\":\"jsonschema\":\"database\":\"model\":\"OracleConfiguration\",
\"properties\":{
\"numberOfConnection\":{
\"type\":\"integer\"
},
\"connectionDate\":{
\"type\":\"integer\",
\"format":\"utc-millisec\"
},
\"isconnected\":{
\"type\":\"boolean\"
}
}
}"
}
Problems with above output:
- I want to remove id property from the string.
- I am getting that weird extra backslash for escape character. I do not see that while debugging and executing this line : mapper.writeValueAsString(schema).But I see that backslash and extra quotes after I set to property.
Any idea how to resolve these?