Here you can find the source of encode(Object obj)
Parameter | Description |
---|---|
obj | a parameter |
public static String encode(Object obj)
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.Writer; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; public class Main { /**/*from www. j a v a2 s . c om*/ * json encode * @param obj * @return json * @author sinmetal */ public static String encode(Object obj) { try { return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS).writeValueAsString(obj); } catch (IOException e) { throw new IllegalStateException(e); } } public static void encode(Writer writer, Object obj) { try { new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS).writeValue(writer, obj); } catch (IOException e) { throw new IllegalStateException(); } } }