Example usage for com.fasterxml.jackson.databind ObjectMapper ObjectMapper

List of usage examples for com.fasterxml.jackson.databind ObjectMapper ObjectMapper

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind ObjectMapper ObjectMapper.

Prototype

public ObjectMapper() 

Source Link

Document

Default constructor, which will construct the default JsonFactory as necessary, use SerializerProvider as its SerializerProvider , and BeanSerializerFactory as its SerializerFactory .

Usage

From source file:com.torchmind.stockpile.client.Stockpile.java

/**
 * Creates a client instance for the specified base URL.
 *
 * @param baseUrl a base URL.//from  ww w  .ja  v a2s  .c  o  m
 * @return a client instance.
 */
@Nonnull
static Stockpile create(@Nonnull String baseUrl) {
    ObjectMapper mapper = new ObjectMapper();
    mapper.findAndRegisterModules();

    Retrofit retrofit = (new Retrofit.Builder()).addConverterFactory(JacksonConverterFactory.create(mapper))
            .baseUrl(baseUrl).build();

    return retrofit.create(Stockpile.class);
}

From source file:io.ventu.rpc.amqp.defaults.DefaultSerializer.java

/**
 * Construct {@code DefaultSerializer} with a default {@code ObjectMapper}.
 */
public DefaultSerializer() {
    this(new ObjectMapper());
}

From source file:org.usd.edu.btl.cli.ConvertBioextract.java

public void toBets(String inputS, String output) {
    ObjectMapper mapper = new ObjectMapper(); //create new Jackson Mapper
    File input = new File(inputS);

    BioExtV1 bioExtTool;/*from  w w w .  j  a  v  a2  s .  com*/

    try {
        //map input json files to iplant class
        bioExtTool = mapper.readValue(input, BioExtV1.class);

        BETSV1 bets = BioExtConverter.toBETS(bioExtTool); //pass the iplant tool spec, convert to bets
        ObjectWriter ow = mapper.writer().withDefaultPrettyPrinter();
        String betsJson = ow.writeValueAsString(bets); //write Json as String
        if (output == null) {
            /*===============PRINT JSON TO CONSOLE AND FILES =================== */
            System.out.println("************************************************\n"
                    + "*********PRINTING OUT CONVERSION************\n"
                    + "----------BioExtract --> Bets--------------\n"
                    + "************************************************\n");
            //print objects as Json using jackson

            System.out.println("=== BioExt TO BETS JSON === \n" + betsJson);

        } else {
            //write to files
            ow.writeValue(new File(output), betsJson);
            System.out.println(output + " has been created successfully");
            System.exit(1);

        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
}

From source file:retsys.client.json.JsonHelper.java

public JsonHelper() {
    mapper = new ObjectMapper();
    mapper.setSerializationInclusion(Include.NON_NULL);
}

From source file:com.computationnode.Multiplier.java

@POST
@Consumes(MediaType.APPLICATION_JSON)//from   ww  w  . j  a v  a2 s .c o  m
@Produces(MediaType.APPLICATION_JSON)
public Response multiply(String inputValues) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    String responseString = new String();
    try {
        Double[] inputArray = mapper.readValue(inputValues, Double[].class);
        if (inputArray.length % 2 != 0) {
            return Response.serverError().entity("Something wrong").build();
        }
        double[] resultArray = new double[inputArray.length / 2];
        for (int i = 0; i < inputArray.length; i += 2) {
            resultArray[i / 2] = inputArray[i] * inputArray[i + 1];
        }
        responseString = mapper.writeValueAsString(resultArray);
    } catch (IOException e) {
        return Response.serverError().entity(e.toString()).build();
    }
    return Response.ok(responseString, MediaType.APPLICATION_JSON).build();
}

From source file:com.hp.autonomy.hod.client.warning.HodWarningTest.java

@Test
public void testFromJson() throws IOException {
    final InputStream jsonStream = getClass()
            .getResourceAsStream("/com/hp/autonomy/hod/client/warning/warning.json");

    final ObjectMapper mapper = new ObjectMapper();

    final HodWarning warning = mapper.readValue(jsonStream, HodWarning.class);

    assertThat(warning.getCode(), is(HodWarningCode.PROCESSING_QUERY_MANIPULATION_PROMOTION_ERROR));
    assertEquals(warning.getDetails(),/*  w ww .  j a v a  2s  . com*/
            "{\"reason\":\"Document for reference 161-23/12/2015-11:00 and index tvguide2 is missing.\"}");
}

From source file:com.yahoo.elide.contrib.swagger.SwaggerIT.java

@Test
void testDocumentFetch() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode node = mapper.readTree(RestAssured.get("/doc/test").asString());
    Assert.assertNotNull(node.get("paths").get("/book"));
}

From source file:org.usd.edu.btl.cli.ConvertBld.java

public void toBets(String inputS, String output) {
    ObjectMapper bldMapper = new ObjectMapper(); //create new Jackson Mapper
    File input = new File(inputS);

    BLDV1 bldTool; //create new seqTool
    ObjectWriter oW = bldMapper.writer().withDefaultPrettyPrinter();
    try {//from w w w. ja  v  a  2  s. c o  m
        //map input json files to iplant class
        bldTool = bldMapper.readValue(input, BLDV1.class);
        //            String seqInputJson = oW.writeValueAsString(bldTool); //write Json as String
        //            System.out.println("=====BLD INPUT FILE =====");
        //            System.out.println(seqInputJson);

        BETSV1 betsOutput = BLDConverter.toBETS(bldTool);
        String betsOutputJson = oW.writeValueAsString(betsOutput); //write Json as String
        if (output == null) {
            /*===============PRINT JSON TO CONSOLE AND FILES =================== */
            System.err.println("************************************************\n"
                    + "*********PRINTING OUT FIRST CONVERSION************\n"
                    + "--------------Seq --> BETS--------------\n"
                    + "************************************************\n");
            //print objects as Json using jackson

            System.err.println("=== BLD TO BETS JSON - OUTPUT === \n");
            System.out.println(betsOutputJson);
        } else {
            System.err.println("Writing to file...");
            //write to files
            oW.writeValue(new File(output), betsOutput);
            System.err.println(output + " has been created successfully");
            System.exit(1);
        }
    } catch (IOException e) {
        System.out.println(e.getMessage());
    }
}

From source file:org.nuxeo.client.api.marshaller.NuxeoConverterFactory.java

public static NuxeoConverterFactory create() {
    // TODO JAVACLIENT-21
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    return create(objectMapper);
}

From source file:org.springframework.social.twitter.api.impl.StreamEventMixin.java

private static TwitterProfile toProfile(final JsonNode node) throws IOException {
    if (null == node || node.isNull() || node.isMissingNode()) {
        return null;
    }/*from w ww .j a v a2s .co m*/
    final ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new TwitterModule());
    return mapper.reader(TwitterProfile.class).readValue(node);
}