Java Object to Json writeValueAsString(Object obj)

Here you can find the source of writeValueAsString(Object obj)

Description

write Value As String

License

Open Source License

Declaration

public static String writeValueAsString(Object obj) throws JsonProcessingException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

public class Main {
    private static ObjectMapper objectMapper = new ObjectMapper()
            .setSerializationInclusion(JsonInclude.Include.NON_NULL)
            .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

    public static String writeValueAsString(Object obj) throws JsonProcessingException {
        return objectMapper.writeValueAsString(obj);
    }/*ww w .java  2 s. c  o m*/
}

Related

  1. toJsonString(T value)
  2. writeJSON(HashMap data)
  3. writeValueAsBytes(Object value)
  4. writeValueAsIndentString(Object value)
  5. writeValueAsString(Object o)
  6. writeValueAsString(Object obj)