Search in sources :

Example 26 with GsonBuilder

use of com.google.gson.GsonBuilder in project play-cookbook by spinscale.

the class ApiPlugin method onApplicationStart.

@Override
public void onApplicationStart() {
    try {
        List<ApplicationClass> applicationClasses = Play.classes.getAnnotatedClasses(XmlRootElement.class);
        List<Class> classes = new ArrayList<Class>();
        for (ApplicationClass applicationClass : applicationClasses) {
            classes.add(applicationClass.javaClass);
        }
        jc = JAXBContext.newInstance(classes.toArray(new Class[] {}));
    } catch (JAXBException e) {
        Logger.error(e, "Problem initializing jaxb context: %s", e.getMessage());
    }
    gson = new GsonBuilder().create();
    Logger.info("ApiPlugin loaded");
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) ApplicationClass(play.classloading.ApplicationClasses.ApplicationClass) ApplicationClass(play.classloading.ApplicationClasses.ApplicationClass)

Example 27 with GsonBuilder

use of com.google.gson.GsonBuilder in project play-cookbook by spinscale.

the class ApiPlugin method onApplicationStart.

public void onApplicationStart() {
    Logger.info("ApiPlugin loaded");
    try {
        List<ApplicationClass> applicationClasses = Play.classes.getAnnotatedClasses(XmlRootElement.class);
        List<Class> classes = new ArrayList<Class>();
        for (ApplicationClass applicationClass : applicationClasses) {
            classes.add(applicationClass.javaClass);
        }
        jc = JAXBContext.newInstance(classes.toArray(new Class[] {}));
    } catch (JAXBException e) {
        Logger.error(e, "Problem initializing jaxb context: %s", e.getMessage());
    }
    gson = new GsonBuilder().create();
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) ApplicationClass(play.classloading.ApplicationClasses.ApplicationClass) ApplicationClass(play.classloading.ApplicationClasses.ApplicationClass)

Example 28 with GsonBuilder

use of com.google.gson.GsonBuilder in project android-app by spark.

the class WebHelpers method initialize.

// should be called during Application.onCreate() to ensure availability
public static void initialize(Context ctx) {
    if (!initialized) {
        if (AppConfig.useStaging()) {
            okHttpClient = disableTLSforStaging();
        } else {
            okHttpClient = new OkHttpClient();
        }
        gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
        initialized = true;
    }
}
Also used : OkHttpClient(com.squareup.okhttp.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder)

Example 29 with GsonBuilder

use of com.google.gson.GsonBuilder in project spring-framework by spring-projects.

the class GsonFactoryBean method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    GsonBuilder builder = (this.base64EncodeByteArrays ? GsonBuilderUtils.gsonBuilderWithBase64EncodedByteArrays() : new GsonBuilder());
    if (this.serializeNulls) {
        builder.serializeNulls();
    }
    if (this.prettyPrinting) {
        builder.setPrettyPrinting();
    }
    if (this.disableHtmlEscaping) {
        builder.disableHtmlEscaping();
    }
    if (this.dateFormatPattern != null) {
        builder.setDateFormat(this.dateFormatPattern);
    }
    this.gson = builder.create();
}
Also used : GsonBuilder(com.google.gson.GsonBuilder)

Example 30 with GsonBuilder

use of com.google.gson.GsonBuilder in project jstorm by alibaba.

the class ZooKeeperDataViewTest method init.

@BeforeClass
public static void init() {
    String CONFIG_PATH = System.getProperty("user.home") + CONFIG_FILE;
    File file = new File(CONFIG_PATH);
    if (file.exists() == false) {
        SKIP = true;
        return;
    }
    try {
        zkobj = new Zookeeper();
        System.getProperties().setProperty("storm.conf.file", CONFIG_PATH);
        Map conf = Utils.readStormConfig();
        zk = zkobj.mkClient(conf, (List<String>) conf.get(Config.STORM_ZOOKEEPER_SERVERS), conf.get(Config.STORM_ZOOKEEPER_PORT), (String) conf.get(Config.STORM_ZOOKEEPER_ROOT));
        gson = new GsonBuilder().setPrettyPrinting().create();
    } catch (Throwable e) {
        e.printStackTrace();
        SKIP = true;
    }
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Zookeeper(com.alibaba.jstorm.zk.Zookeeper) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) Map(java.util.Map) BeforeClass(org.junit.BeforeClass)

Aggregations

GsonBuilder (com.google.gson.GsonBuilder)222 Gson (com.google.gson.Gson)135 IOException (java.io.IOException)40 Type (java.lang.reflect.Type)24 ArrayList (java.util.ArrayList)24 Map (java.util.Map)24 JsonElement (com.google.gson.JsonElement)20 HashMap (java.util.HashMap)20 Test (org.junit.Test)18 JsonObject (com.google.gson.JsonObject)15 JsonSyntaxException (com.google.gson.JsonSyntaxException)13 Date (java.util.Date)13 List (java.util.List)13 Retrofit (retrofit2.Retrofit)13 InputStream (java.io.InputStream)11 OkHttpClient (okhttp3.OkHttpClient)11 File (java.io.File)9 InputStreamReader (java.io.InputStreamReader)9 JsonParseException (com.google.gson.JsonParseException)8 URL (java.net.URL)8