Class CaJson


  • public class CaJson
    extends Object
    JSON util class for CA
    Author:
    Lijun Liao (xipki)
    • Constructor Detail

      • CaJson

        public CaJson()
    • Method Detail

      • newDefaultObjectMapper

        public static com.fasterxml.jackson.databind.ObjectMapper newDefaultObjectMapper()
      • parseObject

        public static <T> T parseObject​(String json,
                                        Class<T> classOfT)
      • parseObject

        public static <T> T parseObject​(byte[] json,
                                        Class<T> classOfT)
      • parseObject

        public static <T> T parseObject​(InputStream jsonInputStream,
                                        Class<T> classOfT)
                                 throws IOException
        Deserialize the object from the input stream. The specified stream remains open after this method returns.
        Type Parameters:
        T - the object type of serialized object.
        Parameters:
        jsonInputStream - the input stream containing the serialized object.
        classOfT - the class of deserialized object.
        Returns:
        the serialized object
        Throws:
        IOException - if IO error occurs while reading the stream.
      • parseObjectAndClose

        public static <T> T parseObjectAndClose​(InputStream jsonInputStream,
                                                Class<T> classOfT)
                                         throws IOException
        Deserialize the object from the input stream and closes the inputstream. The specified stream is closed after this method returns.
        Type Parameters:
        T - the object type of serialized object.
        Parameters:
        jsonInputStream - the input stream containing the serialized object.
        classOfT - the class of deserialized object.
        Returns:
        the serialized object
        Throws:
        IOException - if IO error occurs while reading the stream.
      • toJSONBytes

        public static byte[] toJSONBytes​(Object obj)
      • toPrettyJson

        public static String toPrettyJson​(Object obj)
      • writeJSON

        public static void writeJSON​(Object object,
                                     OutputStream outputStream)
                              throws IOException
        Serialize the object to the output stream. The specified stream remains open after this method returns.
        Parameters:
        object - object to be serialized.
        outputStream - output stream to which the serialized object is written.
        Throws:
        IOException - if IO error occurs while writting to the stream.
      • writeJSONAndClose

        public static void writeJSONAndClose​(Object object,
                                             OutputStream outputStream)
                                      throws IOException
        Serialize the object to the output stream. The specified stream is closed after this method returns.
        Parameters:
        object - object to be serialized.
        outputStream - output stream to which the serialized object is written.
        Throws:
        IOException - if IO error occurs while writting to the stream.
      • writePrettyJSON

        public static void writePrettyJSON​(Object object,
                                           OutputStream outputStream)
                                    throws IOException
        Serialize the object in pretty format to the output stream. The specified stream remains open after this method returns.
        Parameters:
        object - object to be serialized.
        outputStream - output stream to which the serialized object is written.
        Throws:
        IOException - if IO error occurs while writting to the stream.
      • writePrettyJSONAndClose

        public static void writePrettyJSONAndClose​(Object object,
                                                   OutputStream outputStream)
                                            throws IOException
        Serialize the object in pretty format to the output stream. The specified stream is closed after this method returns.
        Parameters:
        object - object to be serialized.
        outputStream - output stream to which the serialized object is written.
        Throws:
        IOException - if IO error occurs while writting to the stream.