Package com.google.gson

Examples of com.google.gson.Gson.fromJson()


    .enableComplexMapKeySerialization()
    .setDateFormat(DateFormat.LONG)
    .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
    .setVersion(1.0)
    .create();
    Object obj = gson.fromJson(src.getValue(), Object.class);
    try {
      return JSONReadingTypeVisitor.read(obj, values, store, start);
    }
    catch (IOException e) {
      throw RuntimeExceptionFactory.io(values.string(e.getMessage()), null, null);
View Full Code Here


    .setDateFormat(DateFormat.LONG)
    .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
    .setVersion(1.0)
    .create();
    System.err.println("fromJSON1:"+src.getValue());
    Object obj = gson.fromJson(src.getValue(), Object.class);
    System.err.println("fromJSON2:"+start);
    try {
      return JSONReadingTypeVisitor.read(obj, values, store, start);
    }
    catch (IOException e) {
View Full Code Here

    /**
     * Save album via JSON API
     */
    private static void saveAlbumJson() {
        Gson gson = new Gson();
        Album album = gson.fromJson(new InputStreamReader(request.body), Album.class);
        album.replaceDuplicateArtist();
        album.save();
    }

    /**
 
View Full Code Here

      e.printStackTrace();
    }

    // Get metadata for the Module
    List<JsonElement> requestElements = new ArrayList<JsonElement>();
    JsonObject moduleJsonObject = gson.fromJson(output, JsonObject.class);

    JsonElement moduleNameElement = moduleJsonObject.get("moduleName");
    JsonElement moduleDescriptionElement = moduleJsonObject.get("moduleDescription");
    JsonElement moduleVersionElement = moduleJsonObject.get("moduleDescription");
View Full Code Here

    private BatchSpec load(File file) throws IOException {
        Gson gson = new Gson();
        InputStream in = new FileInputStream(file);
        try {
            Reader reader = new InputStreamReader(in, Constants.ENCODING);
            BatchSpec result = gson.fromJson(reader, BatchSpec.class);
            reader.close();
            return result;
        } finally {
            in.close();
        }
View Full Code Here

            final Gson gson = new Gson();
            final String postData = gson.toJson(data);
            post.setRequestEntity(new StringRequestEntity(postData, "application/json", "UTF-8"));
            final int status = client.executeMethod(post);
            if (status != 200) throw new RuntimeException("Return Status Code "+post.getStatusCode()+" "+post.getStatusLine());
            return gson.fromJson(post.getResponseBodyAsString(), resultType);
        } catch (Exception e) {
            throw new RuntimeException("Error executing request to "+url+" with "+data+":" + e.getMessage());
        }
    }
View Full Code Here

    }

    public static <T> T decode(Context context, Scriptable scope, Object value, Class<T> type) {
        Object json = NativeJSON.stringify(context, scope, value, null, null);
        Gson gson = new Gson();
        return gson.fromJson((String) json, type);
    }

    public static <T> T decode(Context context, Scriptable scope, Object value, TypeToken<T> type) {
        Object json = NativeJSON.stringify(context, scope, value, null, null);
        Gson gson = new Gson();
View Full Code Here

    }

    public static <T> T decode(Context context, Scriptable scope, Object value, TypeToken<T> type) {
        Object json = NativeJSON.stringify(context, scope, value, null, null);
        Gson gson = new Gson();
        return gson.fromJson((String) json, type.getType());
    }

    public static <T> Predicate<T> getPredicate(final Context context, final Scriptable thisObj, final Function predicate) {
        return new JavaScriptPredicate<T>(context, thisObj, predicate);
    }
View Full Code Here

            //String[] column = gson.fromJson(test, Object[][].class);
          //  Object[][] column = new Gson().fromJson(jsonEjemplo, Object[][].class);
            Gson gson = new Gson();
                  
                   
                    List<Category> table = gson.fromJson(jsonEjemplo, new TypeToken<List<Category>>(){}.getType());
              
                    for (Category tab : table) {
                        System.out.println("Away Team:  " + tab.getDescription());
                        System.out.println("Away Team:  " + tab.getResult().getfNum());
                    }
View Full Code Here

            //String[] column = gson.fromJson(test, Object[][].class);
          //  Object[][] column = new Gson().fromJson(jsonEjemplo, Object[][].class);
            Gson gson = new Gson();
                   
                   
                    List<Category> table = gson.fromJson(jsonEjemplo, new TypeToken<List<Category>>(){}.getType());
                String salida;
                    for (Category tab : table) {
                      System.out.println("#########");
                      System.out.println("ID:  " + tab.getId());
                      System.out.println("Subtitle:  " + tab.getSubtitle());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.