google-code-export / wiquery

Automatically exported from code.google.com/p/wiquery
MIT License
1 stars 1 forks source link

add "json" method into the JsUtils #161

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
wiQuery uses the jackson api for the autocomplete component. Maybe we can offer 
some methods to generate json.

Original issue reported on code.google.com by roche....@gmail.com on 16 Feb 2011 at 8:24

GoogleCodeExporter commented 9 years ago
jackson is best used using annotations and the ObjectMapper. See

https://github.com/hielkehoeve/wiquery-jqplot/blob/master/src/main/java/nl/topic
us/wqplot/components/JQPlot.java
and 
https://github.com/hielkehoeve/wiquery-jqplot/blob/master/src/main/java/nl/topic
us/wqplot/options/PlotAxes.java

Original comment by hielke.hoeve on 16 Feb 2011 at 1:55

GoogleCodeExporter commented 9 years ago
Of course, I mean generate some json with jackson (not with our own methods)

Original comment by roche....@gmail.com on 16 Feb 2011 at 2:25

GoogleCodeExporter commented 9 years ago
Fixed in r719

Just a little method:

/**
     * Method using the jackson API to generate a json representation of your
     * Java object
     * @param jsonObject A serializable object
     * @return the json representation as a string
     * @throws IOException Exeption during the process
     */
    public static String json(Serializable jsonObject) throws IOException {
        StringWriter sw = new StringWriter();
        JsonGenerator gen = new JsonFactory().createJsonGenerator(sw);
        new ObjectMapper().writeValue(gen, jsonObject);
        return sw.toString();
    }

Original comment by roche....@gmail.com on 27 Feb 2011 at 2:05