I have single key-value pair that I need to convert to Json using Gson. How might I do that? Say I have
class MyClass{
  String key;
  String value;
  ...//bunch of other fields
  public String singleKeyValueToJson(){
    return new Gson(key,value);//how do I do this?
  }
}
Notice I am not serializing the whole class: just the two fields.
why don't you create your json manually instead of using library.
public String singleKeyValueToJson(){
    JSONObject json=new JSONObject();
    json.put(key,value);
    return json.toString();
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With