use of com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule in project fabric8 by jboss-fuse.
the class JsonSchemaLookup method init.
public void init() {
LOG.log(Level.INFO, "Creating JsonSchemaLookup instance");
try {
if (mapper == null) {
mapper = new ObjectMapper();
mapper.setVisibilityChecker(new IgnorePropertiesBackedByTransientFields(mapper.getVisibilityChecker()));
JaxbAnnotationModule module1 = new JaxbAnnotationModule();
mapper.registerModule(module1);
BeanValidationAnnotationModule module2 = new BeanValidationAnnotationModule();
mapper.registerModule(module2);
}
// now lets expose the mbean...
singleton = this;
} catch (Exception e) {
LOG.log(Level.WARNING, "Exception during initialization: ", e);
throw new RuntimeException(e);
}
}
use of com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule in project wechat by dllwh.
the class JsonMapper method enableJaxbAnnotation.
/**
* 支持使用Jaxb的Annotation,使得POJO上的annotation不用与Jackson耦合。
* 默认会先查找jaxb的annotation,如果找不到再找jackson的。
*/
public JsonMapper enableJaxbAnnotation() {
JaxbAnnotationModule module = new JaxbAnnotationModule();
this.registerModule(module);
return this;
}
use of com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule in project open-ecard by ecsec.
the class MessageTest method testHelloRequest.
@Test
public void testHelloRequest() throws JsonProcessingException, IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JaxbAnnotationModule());
HelloRequestType req = new HelloRequestType();
req.setSessionIdentifier("1234abcd");
req.setChallenge(new byte[] { 0, 1, 2, 3 });
req.setVersion("1.2.3");
String result = mapper.writeValueAsString(req);
HelloRequestType req1 = mapper.readValue(result, HelloRequestType.class);
// load reference
String inputRef = "{\"Challenge\" : \"00010203\", \"Version\" : \"1.2.3\", \"SessionIdentifier\" : \"1234abcd\"}";
HelloRequestType reference = mapper.readValue(inputRef, HelloRequestType.class);
Assert.assertEquals(reference.getSessionIdentifier(), req1.getSessionIdentifier());
Assert.assertEquals(reference.getChallenge(), req1.getChallenge());
Assert.assertEquals(reference.getVersion(), req1.getVersion());
}
use of com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule in project cloudstack by apache.
the class CSJacksonAnnotationTest method test.
@Test
@Ignore
public void test() {
ObjectMapper mapper = new ObjectMapper();
JaxbAnnotationModule jaxbModule = new JaxbAnnotationModule();
jaxbModule.setPriority(Priority.SECONDARY);
mapper.registerModule(jaxbModule);
mapper.registerModule(new CSJacksonAnnotationModule());
StringWriter writer = new StringWriter();
TestVO vo = new TestVO(1000, "name");
vo.names = new ArrayList<String>();
vo.names.add("name1");
vo.names.add("name2");
vo.values = new HashMap<String, Long>();
vo.values.put("key1", 1000l);
vo.values.put("key2", 2000l);
vo.vo2.name = "testvoname2";
vo.pods = "abcde";
try {
mapper.writeValue(writer, vo);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.print(writer.getBuffer().toString());
}
use of com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule in project CFLint by cflint.
the class ConfigUtils method marshalJson.
public static String marshalJson(final Object obj) throws IOException {
final StringWriter sw = new StringWriter();
final ObjectMapper objectMapper = new ObjectMapper();
final JaxbAnnotationModule module = new JaxbAnnotationModule();
objectMapper.registerModule(module);
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
objectMapper.writeValue(sw, obj);
return sw.toString();
}
Aggregations