Android Open Source - geocamTalkAndroid Talk Json Converter






From Project

Back to project page geocamTalkAndroid.

License

The source code is released under:

NASA OPEN SOURCE AGREEMENT VERSION 1.3 THIS OPEN SOURCE AGREEMENT ("AGREEMENT") DEFINES THE RIGHTS OF USE, REPRODUCTION, DISTRIBUTION, MODIFICATION AND REDISTRIBUTION OF CERTAIN COMPUTER SOFTWARE ORI...

If you think the Android project geocamTalkAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

// __BEGIN_LICENSE__
// Copyright (C) 2008-2010 United States Government as represented by
// the Administrator of the National Aeronautics and Space Administration.
// All Rights Reserved.
// __END_LICENSE__
// w  ww . j  a  va  2 s.c  om
package gov.nasa.arc.geocam.talk.service;

import gov.nasa.arc.geocam.talk.bean.GeoCamTalkMessage;

import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;

/**
 * The Class TalkJsonConverter.
 */
public class TalkJsonConverter
    implements ITalkJsonConverter {

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.ITalkJsonConverter#deserializeList(java.lang.String)
   */
  @Override
  public List<GeoCamTalkMessage> deserializeList(String jsonString) {
    JsonParser parser = new JsonParser();
    JsonObject root = parser.parse(jsonString).getAsJsonObject();
    
    String jsonMessages = root.get("ms").toString();
    
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat("MM/dd/yy HH:mm:ss");
    Gson gson = builder.create();
    
    Type listType = new TypeToken<List<GeoCamTalkMessage>>(){}.getType();
    
    return gson.fromJson(jsonMessages, listType);
  }

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.ITalkJsonConverter#deserialize(java.lang.String)
   */
  @Override
  public GeoCamTalkMessage deserialize(String jsonString) {
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat("MM/dd/yy HH:mm:ss");
    
    Gson gson = builder.create();
    return gson.fromJson(jsonString, GeoCamTalkMessage.class);
  }
  

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.ITalkJsonConverter#serialize(gov.nasa.arc.geocam.talk.bean.GeoCamTalkMessage)
   */
  @Override
  public String serialize(GeoCamTalkMessage message) {
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat("MM/dd/yy HH:mm:ss");
    
    builder.setExclusionStrategies(new TalkMessageExclusionStrategy());
    Gson gson = builder.create();
    String ret= gson.toJson(message);
    return ret;
  }
  
  /**
   * The Class TalkMessageExclusionStrategy.
   */
  public class TalkMessageExclusionStrategy implements ExclusionStrategy {
        
        /* (non-Javadoc)
         * @see com.google.gson.ExclusionStrategy#shouldSkipField(com.google.gson.FieldAttributes)
         */
        @Override
    public boolean shouldSkipField(FieldAttributes f) {
            return (f.getName().equals("audio"));
        }

    /* (non-Javadoc)
     * @see com.google.gson.ExclusionStrategy#shouldSkipClass(java.lang.Class)
     */
    @Override
    public boolean shouldSkipClass(Class<?> arg0) {
      return false;
    }

    }

  /* (non-Javadoc)
   * @see gov.nasa.arc.geocam.talk.service.ITalkJsonConverter#createMap(java.lang.String)
   */
  @Override
  public Map<String, String> createMap(String jsonString) {
    Gson gson = new Gson();
    Type mapType = new TypeToken<Map<String, String>>(){}.getType();
    return gson.fromJson(jsonString, mapType);
  }
}




Java Source Code List

gov.nasa.arc.geocam.talk.GeoCamTalkModule.java
gov.nasa.arc.geocam.talk.GeoCamTalkRoboApplication.java
gov.nasa.arc.geocam.talk.UIUtils.java
gov.nasa.arc.geocam.talk.activity.AuthenticatedBaseActivity.java
gov.nasa.arc.geocam.talk.activity.GeoCamTalkActivity.java
gov.nasa.arc.geocam.talk.activity.GeoCamTalkCreateActivity.java
gov.nasa.arc.geocam.talk.activity.GeoCamTalkLogon.java
gov.nasa.arc.geocam.talk.activity.GeoCamTalkMapActivity.java
gov.nasa.arc.geocam.talk.activity.GeoCamTalkMessageAdapter.java
gov.nasa.arc.geocam.talk.activity.SettingsActivity.java
gov.nasa.arc.geocam.talk.bean.GeoCamTalkMessage.java
gov.nasa.arc.geocam.talk.bean.ServerResponse.java
gov.nasa.arc.geocam.talk.bean.TalkServerIntent.java
gov.nasa.arc.geocam.talk.exception.AuthenticationFailedException.java
gov.nasa.arc.geocam.talk.service.AudioPlayer.java
gov.nasa.arc.geocam.talk.service.AudioRecorder.java
gov.nasa.arc.geocam.talk.service.C2DMReciever.java
gov.nasa.arc.geocam.talk.service.DatabaseHelper.java
gov.nasa.arc.geocam.talk.service.GeoCamSynchronizationTimerTask.java
gov.nasa.arc.geocam.talk.service.GeoLocationListener.java
gov.nasa.arc.geocam.talk.service.IAudioPlayer.java
gov.nasa.arc.geocam.talk.service.IAudioRecorder.java
gov.nasa.arc.geocam.talk.service.IDatabaseHelper.java
gov.nasa.arc.geocam.talk.service.IGeoCamSynchronizationTimerTask.java
gov.nasa.arc.geocam.talk.service.IIntentHelper.java
gov.nasa.arc.geocam.talk.service.IMessageStore.java
gov.nasa.arc.geocam.talk.service.ISiteAuth.java
gov.nasa.arc.geocam.talk.service.ITalkJsonConverter.java
gov.nasa.arc.geocam.talk.service.ITalkServer.java
gov.nasa.arc.geocam.talk.service.IntentHelper.java
gov.nasa.arc.geocam.talk.service.MessageStore.java
gov.nasa.arc.geocam.talk.service.SiteAuthCookie.java
gov.nasa.arc.geocam.talk.service.TalkJsonConverter.java
gov.nasa.arc.geocam.talk.service.TalkMapOverlay.java
gov.nasa.arc.geocam.talk.service.TalkServer.java