Example usage for com.fasterxml.jackson.module.jaxb JaxbAnnotationIntrospector JaxbAnnotationIntrospector

List of usage examples for com.fasterxml.jackson.module.jaxb JaxbAnnotationIntrospector JaxbAnnotationIntrospector

Introduction

In this page you can find the example usage for com.fasterxml.jackson.module.jaxb JaxbAnnotationIntrospector JaxbAnnotationIntrospector.

Prototype

public JaxbAnnotationIntrospector() 

Source Link

Usage

From source file:dk.lnj.swagger4ee.AbstractJSonTest.java

public void makeCompare(SWRoot root, String expFile) throws IOException {

    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
    // make deserializer use JAXB annotations (only)
    mapper.setAnnotationIntrospector(introspector);
    // make serializer use JAXB annotations (only)

    StringWriter sw = new StringWriter();
    mapper.writeValue(sw, root);/*www . ja v a  2  s.  c  o m*/
    mapper.writeValue(new FileWriter(new File("lasttest.json")), root);

    String actual = sw.toString();
    String expected = new String(Files.readAllBytes(Paths.get(expFile)));

    String[] exp_split = expected.split("\n");
    String[] act_split = actual.split("\n");

    for (int i = 0; i < exp_split.length; i++) {
        String exp = exp_split[i];
        String act = act_split[i];
        String shortFileName = expFile.substring(expFile.lastIndexOf("/"));
        Assert.assertEquals(shortFileName + ":" + (i + 1), superTrim(exp), superTrim(act));
    }

}

From source file:com.cloudera.api.ApiObjectMapper.java

public ApiObjectMapper() {
    // Print the JSON with indentation (ie. pretty print)
    configure(SerializationFeature.INDENT_OUTPUT, true);

    // Allow JAX-B annotations.
    setAnnotationIntrospector(new AnnotationIntrospector.Pair(
            getSerializationConfig().getAnnotationIntrospector(), new JaxbAnnotationIntrospector()));

    // Make Jackson respect @XmlElementWrapper.
    enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME);

    // Print all dates in ISO8601 format
    setDateFormat(makeISODateFormat());/*from w ww .  j  a  v a2s  .co  m*/
}

From source file:com.danperron.gamesdbclient.impl.GamesDBClientImpl.java

public GamesDBClientImpl(ExecutorService executorService) {
    xmlMapper = new XmlMapper();
    xmlMapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector());
    xmlMapper.registerModule(new JaxbAnnotationModule());
    xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    this.executorService = executorService;
}

From source file:it.itis.pertini.falessi.tunes.TunesContextListener.java

@Override
protected Injector getInjector() {
    return Guice.createInjector(new JerseyServletModule() {

        @Override/*from w w  w .  ja  va 2  s.  c om*/
        protected void configureServlets() {
            // get and binds JDBC properties
            Names.bindProperties(binder(), loadProperties("jdbc.properties"));
            bind(Properties.class).toInstance(loadProperties("queries.properties"));

            // bind JDBC components
            bind(DataSource.class).toProvider(BasicDataSourceProvider.class).in(SINGLETON);
            bind(QueryRunner.class).toProvider(QueryRunnerProvider.class).in(SINGLETON);
            bind(AuthorHandler.class);
            bind(AuthorListHandler.class);
            bind(AlbumHandler.class);
            bind(AlbumListHandler.class);
            bind(TrackHandler.class);
            bind(TrackListHandler.class);

            // JSON serializer
            bind(JacksonJsonProvider.class).toInstance(new JacksonJsonProvider(
                    new ObjectMapper().setAnnotationIntrospector(new JaxbAnnotationIntrospector())));

            // main servlet
            serve("/*").with(GuiceContainer.class);

            // bind services
            bind(AuthorService.class);
            bind(AlbumService.class);
            bind(TrackService.class);
        }

    });
}

From source file:br.com.dgimenes.jsonlibscomparison.JSONLibsTest.java

private static String encodeWithJACKSONJAXB(SalesJAXB salesAnnotatedWithJAXB)
        throws JsonGenerationException, JsonMappingException, IOException {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ObjectMapper mapper = new ObjectMapper();
    @SuppressWarnings("deprecation")
    AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
    // enables "JAXB annotations only" mode
    mapper.setAnnotationIntrospector(introspector);
    mapper.writeValue(outputStream, salesAnnotatedWithJAXB);
    return outputStream.toString();
}

From source file:com.unilever.audit.services2.Sync_Down.java

/**
 * Retrieves representation of an instance of
 * com.unilever.audit.services2.AuditResource
 *
 * @param id//from   ww w .ja v a  2s.c  o m
 * @param dataType
 * @return an instance of java.lang.String
 */
@GET
@Path("getSyncObject/{id}/{dataType}/{compress}")
@Produces("application/json")
public byte[] getSyncObject(@PathParam("id") int id, @PathParam("dataType") String dataType,
        @PathParam("compress") int compress) {

    GZIPOutputStream gzip = null;
    count++;
    ByteArrayOutputStream out = null;
    SyncDownObjects syncDownObjects = getObject(dataType, id);

    try {
        out = new ByteArrayOutputStream();
        gzip = new GZIPOutputStream(out);

        ObjectMapper mapper = new ObjectMapper();
        AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
        AnnotationIntrospector introspector1 = new JacksonAnnotationIntrospector();
        mapper.setAnnotationIntrospectors(introspector, introspector1);
        mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

        //String jsonString = mapper.writeValueAsString(syncDownObjects);
        //JSONObject jsonobject = (JSONObject) new JSONParser().parse(jsonString);
        //gzip.write(jsonobject.toString().getBytes("8859_1"));
        //gzip.write(jsonobject.toString().getBytes("UTF-8"));
        gzip.write(mapper.writeValueAsBytes(syncDownObjects));
        gzip.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    } //catch (ParseException ex) {
      // ex.printStackTrace();
      // }
    System.out.println("======================= count : " + count);
    return out.toByteArray();
}