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

io.ebean.text.json.EJson Maven / Gradle / Ivy

There is a newer version: 15.8.0
Show newest version
package io.ebean.text.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import io.ebean.XBootstrapService;
import io.ebean.service.SpiJsonService;

import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Utility that converts between JSON content and simple java Maps/Lists.
 */
public class EJson {

  private static final SpiJsonService plugin = XBootstrapService.jsonService();

  /**
   * Write the nested Map/List as json.
   */
  public static String write(Object object) throws IOException {
    return plugin.write(object);
  }

  /**
   * Write the nested Map/List as json to the writer.
   */
  public static void write(Object object, Writer writer) throws IOException {
    plugin.write(object, writer);
  }

  /**
   * Write the nested Map/List as json to the jsonGenerator.
   */
  public static void write(Object object, JsonGenerator jsonGenerator) throws IOException {
    plugin.write(object, jsonGenerator);
  }

  /**
   * Write the collection as json array to the jsonGenerator.
   */
  public static void writeCollection(Collection collection, JsonGenerator jsonGenerator) throws IOException {
    plugin.writeCollection(collection, jsonGenerator);
  }

  /**
   * Parse the json and return as a Map additionally specifying if the returned map should
   * be modify aware meaning that it can detect when it has been modified.
   */
  public static Map parseObject(String json, boolean modifyAware) throws IOException {
    return plugin.parseObject(json, modifyAware);
  }

  /**
   * Parse the json and return as a Map.
   */
  public static Map parseObject(String json) throws IOException {
    return plugin.parseObject(json);
  }

  /**
   * Parse the json and return as a Map taking a reader.
   */
  public static Map parseObject(Reader reader, boolean modifyAware) throws IOException {
    return plugin.parseObject(reader, modifyAware);
  }

  /**
   * Parse the json and return as a Map taking a reader.
   */
  public static Map parseObject(Reader reader) throws IOException {
    return plugin.parseObject(reader);
  }

  /**
   * Parse the json and return as a Map taking a JsonParser.
   */
  public static Map parseObject(JsonParser parser) throws IOException {
    return plugin.parseObject(parser);
  }

  /**
   * Parse the json and return as a Map taking a JsonParser and a starting token.
   * 

* Used when the first token is checked to see if the value is null prior to calling this. *

*/ public static Map parseObject(JsonParser parser, JsonToken token) throws IOException { return plugin.parseObject(parser, token); } /** * Parse the json and return as a modify aware List. */ public static List parseList(String json, boolean modifyAware) throws IOException { return plugin.parseList(json, modifyAware); } /** * Parse the json and return as a List. */ public static List parseList(String json) throws IOException { return plugin.parseList(json); } /** * Parse the json and return as a List taking a Reader. */ public static List parseList(Reader reader) throws IOException { return plugin.parseList(reader); } /** * Parse the json and return as a List taking a JsonParser. */ public static List parseList(JsonParser parser) throws IOException { return plugin.parseList(parser); } /** * Parse the json returning as a List taking into account the current token. */ public static List parseList(JsonParser parser, JsonToken currentToken) throws IOException { return plugin.parseList(parser, currentToken); } /** * Parse the json and return as a List or Map. */ public static Object parse(String json) throws IOException { return plugin.parse(json); } /** * Parse the json and return as a List or Map. */ public static Object parse(Reader reader) throws IOException { return plugin.parse(reader); } /** * Parse the json and return as a List or Map. */ public static Object parse(JsonParser parser) throws IOException { return plugin.parse(parser); } /** * Parse the json returning a Set that might be modify aware. */ public static Set parseSet(String json, boolean modifyAware) throws IOException { return plugin.parseSet(json, modifyAware); } /** * Parse the json returning as a Set taking into account the current token. */ public static Set parseSet(JsonParser parser, JsonToken currentToken) throws IOException { return plugin.parseSet(parser, currentToken); } }