flexjson

FlexJSON Exclude Properties Upon Deserialization

笑着哭i 提交于 2019-12-08 03:47:42
问题 I'm receiving a JSON response from a web service, but for various reasons I don't want to have certain properties deserialized in the final response object. For example I have: public class Foo { private String bar; private int baz; //getters & setters } The JSON response I'm getting back has both properties, but upon deserialization I don't want "bar" to be set. The reason for this is that the property they're sending is a long, but ours is a String, so deserializing throws an

Deserializing JSON list into list of objects with Flexjson

谁都会走 提交于 2019-12-07 23:25:25
问题 I'm trying to deserialize the following json: { "books": [ {"id":"1","name":"book 1"}, {"id":"2","name":"book 2"} ] } Into a List. It worked before with this json: [ {"id":"1","name":"book 1"}, {"id":"2","name":"book 2"} ] } Using this code: List<Book> items = new JSONDeserializer<ArrayList<Book>>() .use("values", Book.class).deserialize(json, ArrayList.class); But now after looking at multiple examples I am at a loss, is it possible to deserialize directly into a list? 回答1: Taking the sample

How can I deserialize part of a JSON string into an object, using FlexJSON?

对着背影说爱祢 提交于 2019-12-07 16:38:10
问题 I'm trying to serialze part of a JSON string into an object. The JSON string looks as follows: {"error":null,"excludeFields":null,"message":null,"success":{"user":{"name":null,"organizationId":100,"username":"nl4321"}}} I only need the user-part of the JSON string, which corresponds to an object of the following class: public class UserForm implements Serializable { private static final long serialVersionUID = -5033294929007794646L; private String username; private String name; @Getter

FlexJson deserialization with custom ObjectFactories

ε祈祈猫儿з 提交于 2019-12-07 02:24:27
I am using FlexJson to support my entities with JSON. But I do have some problems deserializing them, because I want a "short data amount" to reduce the data volume sent between backend and client. Lets suggest we do have a Person class which references to an address: public class Person { private String firstname; private String surname; private Address address; } So what I now want is, to deserialize an Person object containing just the address id and loading the address via this id from the database. { "firstname":"Michael", "surname":"Blomkvist", "addressid":"1" } Any suggestions how to

Deserializing JSON list into list of objects with Flexjson

我的梦境 提交于 2019-12-06 07:37:34
I'm trying to deserialize the following json: { "books": [ {"id":"1","name":"book 1"}, {"id":"2","name":"book 2"} ] } Into a List. It worked before with this json: [ {"id":"1","name":"book 1"}, {"id":"2","name":"book 2"} ] } Using this code: List<Book> items = new JSONDeserializer<ArrayList<Book>>() .use("values", Book.class).deserialize(json, ArrayList.class); But now after looking at multiple examples I am at a loss, is it possible to deserialize directly into a list? Taking the sample from @vikke I successfully applied the deserialization of a list of longs. List<Long> idsLong = new

Android array to Sharedpreferences with Gson

流过昼夜 提交于 2019-12-06 04:21:51
I need to create an array of the last 5 call dates. I know that I have to save the date on the array but I don't know how to reorder the other records to keep this last call date the 1st record. And always maintain only 5 records The Goal is to save that last call string and add to the array, after that I reorder to and maintain only the 5 records, after that I use FlexJson to make a string and save on sharedpreferences. Anyone have this full process? Here what I'm doing but is throwing errors everywhere: SAVE SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss dd-MM-yyyy", Locale.getDefault(

How can I deserialize part of a JSON string into an object, using FlexJSON?

风流意气都作罢 提交于 2019-12-06 02:30:27
I'm trying to serialze part of a JSON string into an object. The JSON string looks as follows: {"error":null,"excludeFields":null,"message":null,"success":{"user":{"name":null,"organizationId":100,"username":"nl4321"}}} I only need the user-part of the JSON string, which corresponds to an object of the following class: public class UserForm implements Serializable { private static final long serialVersionUID = -5033294929007794646L; private String username; private String name; @Getter @Setter private int organizationId; public UserForm() { } public UserForm(User user) { if (user != null) {

How to serialize Map<String, List<Object>> with FlexJSON

不问归期 提交于 2019-12-04 12:18:28
I have a object which I want to serialize to JSON. This object is a map with list of a specific objects. This looks similar to it: Map<String, List<Object>> map = new Map<String, List<Object>>(); I am using FlexJSON. I can work only with flexjson.JSONSerializer . There are my tries: JSONSerializer jsonSerializer = new JSONSerializer(); // jsonSerializer.include("map"); // jsonSerializer.include("map.myList.object"); jsonSerializer.transform(new MapTransformer(), "map"); jsonSerializer.exclude("*.class"); As you can see I am trying now with Transformer classes but I haven't succeeded. The

How to use Flexjson JSONDeserializer?

↘锁芯ラ 提交于 2019-12-03 22:36:19
问题 I have a string: [{"product_id":"2","name":'stack"'},{"product_id":"2","name":"overflow"}]" How can I use Flexjson's JSONDeserializer to obtain all product_id s from the above string? I have a class called productinformation which has fields like product_id and name . 回答1: You could use the JSONDeserializer.use() methods to tell it how to deserialize the array and each object in the array, in this case of class ProductInformation . The product_id attribute does not match up with the standard

How to use Flexjson JSONDeserializer?

可紊 提交于 2019-12-01 01:41:22
I have a string: [{"product_id":"2","name":'stack"'},{"product_id":"2","name":"overflow"}]" How can I use Flexjson's JSONDeserializer to obtain all product_id s from the above string? I have a class called productinformation which has fields like product_id and name . You could use the JSONDeserializer.use() methods to tell it how to deserialize the array and each object in the array, in this case of class ProductInformation . The product_id attribute does not match up with the standard naming that flexjson expects, so your properties on the object will need to have an underscore in them.