Package com.google.gson

Examples of com.google.gson.Gson


  }


  public IString toJSON(IValue value) {
    IValueAdapter adap = new IValueAdapter();
    Gson gson = new GsonBuilder()
    .registerTypeAdapter(IValue.class, adap)
    .enableComplexMapKeySerialization()
    .setDateFormat(DateFormat.LONG)
    .setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
    .setVersion(1.0)
    .create();
    try {
      String json = gson.toJson(value, new TypeToken<IValue>() {}.getType());
      return values.string(json);
    } catch (Exception e) {
      throw RuntimeExceptionFactory.io(values.string(e.getMessage()), null, null);
    }
  }
View Full Code Here


    }
  }
  public IValue fromJSON(IValue type, IString src, IEvaluatorContext ctx) {
    TypeStore store = ctx.getCurrentEnvt().getStore();
    Type start = new TypeReifier(ctx.getValueFactory()).valueToType((IConstructor) type, store);
    Gson gson = new GsonBuilder()
    .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

   
    //TypeStore store = ctx.getCurrentEnvt().getStore();
    //Type start = new TypeReifier(ctx.getValueFactory()).valueToType((IConstructor) type, store);
   
    System.err.println("fromJSON0:"+start);
    Gson gson = new GsonBuilder()
    .enableComplexMapKeySerialization()
    .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

   * @return a Module containing all of the requests and metadata for the
   *         given file
   */
  public GarglModule parseAndConvert() {
    // Initialize JSON parser
    Gson gson = new Gson();
    String output = new String();
    try {
      output = readFile(filename);
    } catch (FileNotFoundException e) {
      System.out.println("Error: " + filename
          + " does not exist, please specify another file");
      System.exit(0);
    } catch (IOException e) {
      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

            Long x = offsets.get(scanner.getLiveFile());
            if (x == null) {
                offsets.put(scanner.getLiveFile(), parser.currentOffset());
            }

            final String jsonState = new Gson().toJson(new SpoutState(scanner, offsets));
            final File newState = new File(statusFile.getParentFile(), String.format("%s-%06x", statusFile.getName(), new Random().nextInt()));
            Files.write(jsonState, newState, Charsets.UTF_8);
            Files.move(newState, statusFile);
        } catch (IOException e) {
            log.error(String.format("Unable to write status to %s", statusFile), e);
View Full Code Here

      html_file.close();
  }

  HTMLStatusExtractor hse = new HTMLStatusExtractor();
  JsonObject json = hse.extractTweet(buf.toString());
  Gson gson = new GsonBuilder().setPrettyPrinting().create();
  System.out.println(gson.toJson(json));
    }
View Full Code Here

  private Map<String, List<Feature>> parseJsonResults(List<String> jsonReportFiles) throws IOException {
    Map<String, List<Feature>> featureResults = new LinkedHashMap<String, List<Feature>>();
    for (String jsonFile : jsonReportFiles) {
      if (FileUtils.sizeOf(new File(jsonFile)) > 0) {
        try {
          Feature[] features = new Gson().fromJson(new FileReader(jsonFile), Feature[].class);
          featureResults.put(jsonFile, Arrays.asList(features));
        } catch (JsonSyntaxException e) {
          System.out.println("[WARNING] File " + jsonFile + " is not a valid json report:  " + e.getMessage());
          if (e.getCause() instanceof MalformedJsonException) {
            // malformed json will be handled otherwise silently skip invalid cucumber json report
View Full Code Here

    outputObjects.add("queries", outputJsonArray);
  }


  public String toString() {
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    String json = gson.toJson(outputObjects);
    return json;
  }
View Full Code Here

        return revisions.get(0);
    }

    private List<PageRevision> extractRevisions(final String response) throws ParseException {
        Map<String, Map<String, Map<String, Map<String, Object>>>> result = new Gson().fromJson(response, Map.class);

        List<PageRevision> revisions = newArrayList();

        for (Map<String, Object> p : result.get("query").get("pages").values()) {
            Map<String, Object> lastRevision = ((List<Map<String, Object>>)p.get("revisions")).get(0);
View Full Code Here

TOP

Related Classes of com.google.gson.Gson

Copyright © 2018 www.massapicom. 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.