Search in sources :

Example 11 with JaxbAnnotationModule

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);
    }
}
Also used : JaxbAnnotationModule(com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 12 with JaxbAnnotationModule

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;
}
Also used : JaxbAnnotationModule(com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule)

Example 13 with JaxbAnnotationModule

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());
}
Also used : JaxbAnnotationModule(com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule) HelloRequestType(org.openecard.ws.chipgateway.HelloRequestType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 14 with JaxbAnnotationModule

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());
}
Also used : JaxbAnnotationModule(com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule) StringWriter(java.io.StringWriter) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with JaxbAnnotationModule

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();
}
Also used : JaxbAnnotationModule(com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule) StringWriter(java.io.StringWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JaxbAnnotationModule (com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule)16 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 StringWriter (java.io.StringWriter)3 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)2 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)2 MapperFeature (com.fasterxml.jackson.databind.MapperFeature)2 Module (com.fasterxml.jackson.databind.Module)2 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)2 Swagger (io.swagger.models.Swagger)2 OAuth2Definition (io.swagger.models.auth.OAuth2Definition)2 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)1 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)1 IOException (java.io.IOException)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 HelloRequestType (org.openecard.ws.chipgateway.HelloRequestType)1 Test (org.testng.annotations.Test)1