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