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

src.java.test.TestJavaMapper Maven / Gradle / Ivy

Go to download

Jackson is a high-performance JSON processor (parser, generator)

The newest version!
package test;

import java.io.*;

import org.codehaus.jackson.*;
import org.codehaus.jackson.map.*;

public class TestJavaMapper
{
    private TestJavaMapper() { }

    public static void main(String[] args)
        throws Exception
    {
        if (args.length != 1) {
            System.err.println("Usage: java test.TestJavaMapper ");
            System.exit(1);
        }
        FileInputStream in = new FileInputStream(new File(args[0]));
        JsonFactory f = new JsonFactory();
        JsonParser jp = f.createJsonParser(in);
        JavaTypeMapper jmap = new JavaTypeMapper();
        Object result = jmap.read(jp);
        jp.close();
        System.out.println("Read result ("+(result.getClass())+"): <"+result+">");

        StringWriter sw = new StringWriter();
        JsonGenerator jg = f.createJsonGenerator(sw);
        try {
            jmap.writeValue(jg, result);
        } catch (Exception e) {
            try { jg.flush(); } catch (IOException ioe) { }
            System.err.println("Error, intermediate result = |"+sw+"|");
            throw e;
        }
        jg.close();

        System.out.println("Write result: <"+sw.toString()+">");
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy