All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.jmatrix.db.common.JSONUtil Maven / Gradle / Ivy

The newest version!
package net.jmatrix.db.common;

import java.io.IOException;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

public class JSONUtil {
   
   
   public static  U read(String s, Class u) throws IOException {
      ObjectMapper om=new ObjectMapper();
      om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
      om.enable(SerializationFeature.INDENT_OUTPUT);
      return om.readValue(s, u);
   }
   
   public static String write(Object o)  throws IOException {
      ObjectMapper om=new ObjectMapper();
      om.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
      om.enable(SerializationFeature.INDENT_OUTPUT);
      return om.writeValueAsString(o);
   }
}