Package com.fasterxml.jackson.databind

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


    }
    else {
      ObjectMapper mapper = new ObjectMapper();
      mapper.addMixInAnnotations(RemotingApi.class, RemotingApiMixin.class);
      try {
        jsonConfig = mapper.writer().withDefaultPrettyPrinter()
            .writeValueAsString(remotingApi);
      }
      catch (JsonProcessingException e) {
        jsonConfig = null;
        LogFactory.getLog(ApiController.class)
View Full Code Here


        Integer expectedPort = 80;
        assertEquals(expectedPort, service.getContainerPort().getIntValue());

        ObjectMapper mapper = KubernetesFactory.createObjectMapper();

        mapper.writer().writeValue(System.out, service);
    }

    @Test
    public void testParsePod() throws Exception {
        assertParseExampleFile("pod.json", PodSchema.class);
View Full Code Here

   public void testSerialize() throws Exception
   {
      ObjectMapper mapper = new ObjectMapper();
      Dummy dummy = new Dummy("test", "http://example.com/orders/{orderId}{?view}");
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      mapper.writer().writeValue(out, dummy);
     
      Dummy dummy2 = mapper.readValue(out.toByteArray(), Dummy.class);
     
      Assert.assertEquals("test", dummy2.getName());
      Assert.assertEquals("http://example.com/orders/{orderId}{?view}", dummy2.getTemplate().getTemplate());
View Full Code Here

            }
        } while (sb.length() < 1050);
        final String inputDesc = sb.toString();
        String expOutputDesc = inputDesc.replace("\"", "\"\"");
        String expOutput = "id,\""+expOutputDesc+"\"";
        String result = mapper.writer(schema).writeValueAsString(new IdDesc("id", inputDesc)).trim();
        assertEquals(expOutput, result);
    }

    public void testWriteInFile() throws Exception
    {
View Full Code Here

                .put("firstName", "David")
                .put("lastName", "Douillet");

        File file = File.createTempFile("file", ".csv");
        try {
            mapper.writer(schema.withHeader()).writeValue(file, node);
        } finally {
            file.delete();
        }
    }
View Full Code Here

                .setNullValue("n/a")
                .addColumn("id")
                .addColumn("desc")
                .build();
       
        String result = mapper.writer(schema).writeValueAsString(new IdDesc("id", null));
        // MUST use doubling for quotes!
        assertEquals("id,n/a\n", result);
    }

    /*
 
View Full Code Here

        assertNotNull(wrapper.location);
        assertEquals(15, wrapper.location.x);
        assertEquals(27, wrapper.location.y);

        // should also write out the same way
        assertEquals(CSV, mapper.writer(schema).writeValueAsString(wrapper));
    }

   
    /**
     * Another simple test, but this time auto-generating Schema from
View Full Code Here

        // from base, default order differs:
        // @JsonPropertyOrder({"firstName", "lastName", "gender" ,"verified", "userImage"})
       
        FiveMinuteUser user = new FiveMinuteUser("Silu", "Seppala", false, Gender.MALE,
                new byte[] { 1, 2, 3, 4, 5});
        String csv = mapper.writer(schema).writeValueAsString(user);
        assertEquals("Silu,Seppala,MALE,AQIDBAU=,false\n", csv);
    }

    public void testSimpleWithAutoSchema() throws Exception
    {
View Full Code Here

        CsvSchema schema = CsvSchema.builder()
            .addColumn("id")
            .addColumn("amount")
            .build();

        String result = mapper.writer(schema).writeValueAsString(new Entry("abc", 1.25));
        assertEquals("abc,1.25\n", result);
    }

    public void testExplicitWithFloat() throws Exception
    {
View Full Code Here

                .build();

        float amount = 1.89f;
        //this value loses precision when converted
        assertFalse(Double.toString((double)amount).equals("1.89"));
        String result = mapper.writer(schema).writeValueAsString(new Entry2("abc", amount));
        assertEquals("abc,1.89\n", result);
    }

    public void testExplicitWithQuoted() throws Exception
    {
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.