001package com.avaje.ebean.text.json;
002
003import java.io.IOException;
004import java.io.Reader;
005import java.io.Writer;
006import java.util.Collection;
007import java.util.List;
008import java.util.Map;
009
010import com.fasterxml.jackson.core.JsonGenerator;
011import com.fasterxml.jackson.core.JsonParser;
012import com.fasterxml.jackson.core.JsonToken;
013
014/**
015 * Utility that converts between JSON content and simple java Maps/Lists.
016 */
017public class EJson {
018
019  /**
020   * Write the nested Map/List as json.
021   */
022  public static String write(Object object) throws IOException {
023    return EJsonWriter.write(object);
024  }
025  
026  /**
027   * Write the nested Map/List as json to the writer.
028   */
029  public static void write(Object object, Writer writer) throws IOException {
030    EJsonWriter.write(object, writer);
031  }
032  
033  /**
034   * Write the nested Map/List as json to the jsonGenerator.
035   */
036  public static void write(Object object, JsonGenerator jsonGenerator) throws IOException {
037    EJsonWriter.write(object, jsonGenerator);
038  }
039
040  /**
041   * Write the collection as json array to the jsonGenerator.
042   */
043  public static void writeCollection(Collection<Object> collection, JsonGenerator jsonGenerator) throws IOException {
044    EJsonWriter.writeCollection(collection, jsonGenerator);
045  }
046
047  /**
048   * Parse the json and return as a Map additionally specifying if the returned map should
049   * be modify aware meaning that it can detect when it has been modified.
050   */
051  public static Map<String,Object> parseObject(String json, boolean modifyAware) throws IOException {
052    return EJsonReader.parseObject(json, modifyAware);
053  }
054
055  /**
056   * Parse the json and return as a Map.
057   */
058  public static Map<String,Object> parseObject(String json) throws IOException {
059    return EJsonReader.parseObject(json);
060  }
061
062  /**
063   * Parse the json and return as a Map taking a reader.
064   */
065  public static Map<String,Object> parseObject(Reader reader, boolean modifyAware) throws IOException {
066    return EJsonReader.parseObject(reader, modifyAware);
067  }
068
069  /**
070   * Parse the json and return as a Map taking a reader.
071   */
072  public static Map<String,Object> parseObject(Reader reader) throws IOException {
073    return EJsonReader.parseObject(reader);
074  }
075  
076  /**
077   * Parse the json and return as a Map taking a JsonParser.
078   */
079  public static Map<String,Object> parseObject(JsonParser parser) throws IOException {
080    return EJsonReader.parseObject(parser);
081  }
082
083  /**
084   * Parse the json and return as a Map taking a JsonParser and a starting token.
085   * <p>
086   * Used when the first token is checked to see if the value is null prior to calling this.
087   * </p>
088   */
089  public static Map<String,Object> parseObject(JsonParser parser, JsonToken token) throws IOException {
090    return EJsonReader.parseObject(parser, token);
091  }
092
093  /**
094   * Parse the json and return as a List.
095   * @throws IOException 
096   */
097  public static List<Object> parseList(String json) throws IOException {
098    return EJsonReader.parseList(json);
099  }
100  
101  /**
102   * Parse the json and return as a List taking a Reader.
103   * @throws IOException 
104   */
105  public static List<Object> parseList(Reader reader) throws IOException {
106    return EJsonReader.parseList(reader);
107  }
108  
109  /**
110   * Parse the json and return as a List taking a JsonParser.
111   */
112  public static List<Object> parseList(JsonParser parser) throws IOException {
113    return EJsonReader.parseList(parser);
114  }
115  
116  
117  /**
118   * Parse the json and return as a List or Map.
119   */
120  public static Object parse(String json) throws IOException {
121    return EJsonReader.parse(json);
122  }
123  
124  /**
125   * Parse the json and return as a List or Map.
126   */
127  public static Object parse(Reader reader) throws IOException {
128    return EJsonReader.parse(reader);
129  }
130  
131  /**
132   * Parse the json and return as a List or Map.
133   */
134  public static Object parse(JsonParser parser) throws IOException {
135    return EJsonReader.parse(parser);
136  }
137
138}