Package com.fasterxml.jackson.databind

Examples of com.fasterxml.jackson.databind.ObjectMapper.writeValue()


        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) {
View Full Code Here


            ObjectMapper m = fast ? fastMapper : slowMapper;
            int len = 0;
           
            for (int i = 0; i < 399999; ++i) {
                out.reset();
                m.writeValue(out, bean);
                len = out.size();
            }
            long time = System.currentTimeMillis() - now;
           
            System.out.println("Mapper (fast: "+fast+"; "+len+"); took "+time+" msecs");
View Full Code Here

        try {
            ObjectMapper mapper = new ObjectMapper();

            StringWriter sw = new StringWriter(50 * 1024);

            mapper.writeValue(sw, pojo);

            return sw.toString();
        } catch (IOException e) {
            throw Exceptions.runtime(e);
        }
View Full Code Here

      ServletOutputStream outputStream = response.getOutputStream();

      if (!streamResponse) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
        JsonGenerator jsonGenerator = objectMapper.getJsonFactory().createJsonGenerator(bos, JsonEncoding.UTF8);
        objectMapper.writeValue(jsonGenerator, responseObject);
        response.setContentLength(bos.size());
        outputStream.write(bos.toByteArray());
        jsonGenerator.close();
      } else {
        JsonGenerator jsonGenerator = objectMapper.getJsonFactory().createJsonGenerator(outputStream,
View Full Code Here

        outputStream.write(bos.toByteArray());
        jsonGenerator.close();
      } else {
        JsonGenerator jsonGenerator = objectMapper.getJsonFactory().createJsonGenerator(outputStream,
            JsonEncoding.UTF8);
        objectMapper.writeValue(jsonGenerator, responseObject);
        jsonGenerator.close();
      }

      outputStream.flush();
    }
View Full Code Here

    final ServletOutputStream outputStream = response.getOutputStream();

    if (!streamResponse) {
      ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
      JsonGenerator jsonGenerator = objectMapper.getJsonFactory().createJsonGenerator(bos, JsonEncoding.UTF8);
      objectMapper.writeValue(jsonGenerator, responseObject);
      response.setContentLength(bos.size());
      outputStream.write(bos.toByteArray());
    } else {
      JsonGenerator jsonGenerator = objectMapper.getJsonFactory().createJsonGenerator(outputStream,
          JsonEncoding.UTF8);
View Full Code Here

      response.setContentLength(bos.size());
      outputStream.write(bos.toByteArray());
    } else {
      JsonGenerator jsonGenerator = objectMapper.getJsonFactory().createJsonGenerator(outputStream,
          JsonEncoding.UTF8);
      objectMapper.writeValue(jsonGenerator, responseObject);
    }

    outputStream.flush();
  }
View Full Code Here

                "591b2869-146e-41d7-8048-e8131f1fdec5",
                "82994ac2-7b23-49f2-8cc5-e24cf6ed77be",
        }) {
            TokenBuffer buf = new TokenBuffer(mapper, false); // no ObjectCodec
            UUID uuid = UUID.fromString(value);
            mapper.writeValue(buf, uuid);
            buf.close();
   
            // and bring it back
            UUID out = mapper.readValue(buf.asParser(), UUID.class);
            assertEquals(uuid.toString(), out.toString());
View Full Code Here

    {
        FixtureObject  aTestObj = new FixtureObject();
        ObjectMapper aMapper  = new ObjectMapper();
        StringWriter aWriter = new StringWriter();
        JsonGenerator aGen = new JsonFactory().createGenerator(aWriter);
        aMapper.writeValue(aGen, aTestObj);
        aGen.close();
        JsonParser jp = new JsonFactory().createParser(new StringReader(aWriter.toString()));

        assertEquals(JsonToken.START_OBJECT, jp.nextToken());
View Full Code Here

        try {
            ObjectMapper mapper = new ObjectMapper();

            StringWriter sw = new StringWriter(50 * 1024);

            mapper.writeValue(sw, pojo);

            return sw.toString();
        } catch (IOException e) {
            throw Exceptions.runtime(e);
        }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.