Android Open Source - transloadit-Android-sdk J S O N Request Parser






From Project

Back to project page transloadit-Android-sdk.

License

The source code is released under:

MIT License

If you think the Android project transloadit-Android-sdk 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

package hu.szabot.transloadit.parser;
/*  ww w.j  a v  a  2s . c  o  m*/
import hu.szabot.transloadit.exceptions.NotParseableException;
import hu.szabot.transloadit.log.TransloaditLogger;

import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;


/**The JSON implementation of the IRequsetParser interface*/
public class JSONRequestParser implements IRequestParser{
  
  /**The request parameters*/
  private Map<String, Object> request;

  /**
   * Creates new JSONRequestParser and sets the request properties
   * @param request The params key-value pairs
   */
  public JSONRequestParser(Map<String, Object> request) 
  {
    this.request = request;
  }
  
  /**
   * Creates new JSONRequestParser
   */
  public JSONRequestParser() {}

  @Override
  public Map<String, Object> getRequest() {
    return request;
  }

  @Override
  public void setRequest(Map<String, Object> request) 
  {
    this.request=request;
  }

  @Override
  public String parse() throws NotParseableException 
  {
    try {
      
      return toJson(getRequest()).toString();
      
    } catch (Exception e) 
    {
      TransloaditLogger.logError(getClass(), e,"Not parseable map: %s", request);
      
      throw new NotParseableException();
    }
  }
  
  /**
   * Parse the Map to hierarchical JSON
   * @param params The Map to be parsed
   * @return The created JSONObject
   */
  @SuppressWarnings("unchecked")
  public JSONObject toJson(Map<String,Object> params)
    {
      JSONObject json=new JSONObject();
      
      for(String key: params.keySet())
      {
        if(params.get(key) instanceof Map)
        {
          try {
          json.put(key,toJson((Map<String,Object>)params.get(key)));
        } catch (JSONException e) 
        {}
          
          
        }else
        {
          try {
          json.put(key, params.get(key));
        } catch (JSONException e) 
        {
        }
        }
      }
      
      
        return json;
    }

}




Java Source Code List

hu.szabot.transloadit.ApiData.java
hu.szabot.transloadit.IApiRequest.java
hu.szabot.transloadit.IApiResponse.java
hu.szabot.transloadit.ITransloadit.java
hu.szabot.transloadit.TransloaditRequest.java
hu.szabot.transloadit.TransloaditResponse.java
hu.szabot.transloadit.Transloadit.java
hu.szabot.transloadit.assembly.AssemblyBuilder.java
hu.szabot.transloadit.assembly.IAssemblyBuilder.java
hu.szabot.transloadit.assembly.IStep.java
hu.szabot.transloadit.assembly.Step.java
hu.szabot.transloadit.assembly.exceptions.AlreadyDefinedKeyException.java
hu.szabot.transloadit.assembly.exceptions.InvalidFieldKeyException.java
hu.szabot.transloadit.exceptions.FileNotOpenableException.java
hu.szabot.transloadit.exceptions.NotParseableException.java
hu.szabot.transloadit.executor.DefaultHttpExecutor.java
hu.szabot.transloadit.executor.IRequestExecutor.java
hu.szabot.transloadit.executor.ParsedApiData.java
hu.szabot.transloadit.log.TransloaditLogger.java
hu.szabot.transloadit.parser.IRequestParser.java
hu.szabot.transloadit.parser.IResponseParser.java
hu.szabot.transloadit.parser.JSONRequestParser.java
hu.szabot.transloadit.parser.JSONResponseParser.java
hu.szabot.transloadit.utils.ShaUtils.java