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

io.avaje.json.simple.DSimpleMapper Maven / Gradle / Ivy

There is a newer version: 3.0-RC5
Show newest version
package io.avaje.json.simple;

import io.avaje.json.JsonAdapter;
import io.avaje.json.PropertyNames;
import io.avaje.json.core.CoreTypes;
import io.avaje.json.stream.JsonStream;

import java.util.List;
import java.util.Map;

final class DSimpleMapper implements SimpleMapper {

  private final JsonStream jsonStream;
  private final Type objectType;
  private final Type> mapType;
  private final Type> listType;

  DSimpleMapper(JsonStream jsonStream, CoreTypes.CoreAdapters adapters) {
    this.jsonStream = jsonStream;
    this.objectType = new DTypeMapper<>(adapters.objectAdapter(), jsonStream);
    this.mapType = new DTypeMapper<>(adapters.mapAdapter(), jsonStream);
    this.listType = new DTypeMapper<>(adapters.listAdapter(), jsonStream);
  }

  @Override
  public PropertyNames properties(String... names) {
    return jsonStream.properties(names);
  }

  @Override
  public  Type type(JsonAdapter myAdapter) {
    return new DTypeMapper<>(myAdapter, jsonStream);
  }

  @Override
  public Type object() {
    return objectType;
  }

  @Override
  public Type> map() {
    return mapType;
  }

  @Override
  public Type> list() {
    return listType;
  }

  @Override
  public String toJson(Object object) {
    return objectType.toJson(object);
  }

  @Override
  public Object fromJson(String json) {
    return objectType.fromJson(json);
  }

  @Override
  public Map fromJsonObject(String json) {
    return mapType.fromJson(json);
  }

  @Override
  public List fromJsonArray(String json) {
    return listType.fromJson(json);
  }
}