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

com.testvagrant.optimus.commons.filehandlers.GsonParser Maven / Gradle / Ivy

Go to download

Optimus Lite API to manage test devices and create appium driver based on platform

There is a newer version: 0.1.7-beta
Show newest version
package com.testvagrant.optimus.commons.filehandlers;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;

import java.io.FileReader;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.Map;

public class GsonParser {

  private final Gson gson;

  private GsonParser() {
    this.gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
  }

  public static GsonParser toInstance() {
    return new GsonParser();
  }

  public  String serialize(T object) {
    return gson.toJson(object);
  }

  public  T deserialize(FileReader reader, Class tClass) {
    return gson.fromJson(reader, tClass);
  }

  public  T deserialize(String json, Class tClass) {
    return gson.fromJson(json, tClass);
  }

  public  T deserialize(InputStreamReader streamReader, Class tClass) {
    return gson.fromJson(streamReader, tClass);
  }

  public  T deserialize(JsonElement jsonElement, Class tClass) {
    return gson.fromJson(jsonElement, tClass);
  }

  public Map deserialize(String json, Type tType) {
    return gson.fromJson(json, tType);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy