json « Development « Java I/O Q&A





1. Using JSON serialization as a persistence mechanism instead of RDB    stackoverflow.com

I'm thinking about throwing away my DB in my next project to simplify development/evolution. One way to do it is not to leave the Objects realm at all and persist my objects ...

2. Using Jackson ObjectMapper to serialize the subclass name into JSON, not the superclass    stackoverflow.com

In the following Jackson/Java code that serializes objects into JSON, I am getting this:

{"animal":{"x":"x"}}
However, what I actually want to get is this:
{"dog":{"x":"x"}}
Is there something I can do to AnimalContainer so that ...

3. Is there a Java JSON library that uses the same pattern as XMLEncoder    stackoverflow.com

I have looked at a few JSON libraries for Java, but few of them seem to follow the same serialization pattern as core Java serialization patterns. I would like to ...

4. Convert a JSON string to object in Java?    stackoverflow.com

Is there a way in Java/J2ME to convert a string, such as:

{name:"MyNode", width:200, height:100}
to an internal Object representation of the same, in one line of code? Because the current method is ...

5. JSON, JS to Java and Vice Versa, and other languages    stackoverflow.com

I want to use JSON to represent JS objects send them to a Java program, and vice versa. I would also like to do this for other languages. C# to Java ...

6. Possible to configure Jackson-Json Mapper to exclude properties based on which object it is serializing?    stackoverflow.com

Say I have objects such as a Business with a List of Address objects, and an Order that has a Business. Is it possible to configure so that when the Order is ...

7. How to get List from json string using FlexJson Json serializer in Java?    stackoverflow.com

String episodeIds = "['abc', '123', '456']";
     List<Long> list = new JSONDeserializer<ArrayList<Long>>().use(null, ArrayList.class).deserialize(episodeIds);
     System.out.println(list);
This code returns string but must return LONG)

8. How to recursively serialize an object using reflection?    stackoverflow.com

I want to navigate to the N-th level of an object, and serialize it's properties in String format. For Example:

class Animal {
   public String name;
   public int weight;
 ...

9. Is there a JSON library that can serialize Proxy objects?    stackoverflow.com

Using ActiveObjects as my ORM and Gson as my JSON processor. Ran into a problem going toJson from persisted objects. The problem is that my persisted class is actually an Interface ...





10. Jackson - suppressing serialization(write) of properties dynamically    stackoverflow.com

I am trying to convert java object to JSON object in Tomcat/jersey using Jackson. And want to suppress serialization(write) of certain properties dynamically. I can use JsonIgnore, but I want to make ...

11. How to parse JSON file?    stackoverflow.com

Simple situation -

  1. read a json file
  2. discover all key-value pairs
  3. compare key-value pairs
I tried gson, package from json.org, but can't seem to get far with it. Can someone please provide a clear sample ...

12. Is it an efficient way to serialize JSON data in Java?    stackoverflow.com

I don't know whether this question makes sense or not. I have huge amount of JSON data with me. I am getting that data from Server to the Client side. Is it good ...

13. How to serialize Joda DateTime with Jackson JSON processer?    stackoverflow.com

How do I get Jackson to serialize my Joda DateTime object according to a simple pattern (like "dd-MM-yyyy"? I've tried:

@JsonSerialize(using=DateTimeSerializer.class)
private final DateTime date;
I've tried:
ObjectMapper mapper = new ObjectMapper()
    .getSerializationConfig()
 ...

14. check if file is json, java    stackoverflow.com

Using Java is there an easy way to check whether a given file conforms to json format? Using gson, the best i can do is:

private final JsonParser parser = new JsonParser();
jsonElement = ...

15. Exiftool create several JSon files from just one directory    stackoverflow.com


Does anybody know how could I get severals JSon files by executing just once exiftool.
I could generate one JSon file from my directory, with all metadatas from files inside this folder, ...

16. FlexJSON doesn't serialize class objects fully    stackoverflow.com

Hi
I am new to FlexJson and was following http://flexjson.sourceforge.net/ for simple tutorial.
I wrote a simple program but it seems not to be serializing the object attributes. Please help me ...





17. JSON "flat" serialization with Java    stackoverflow.com

I am looking for a JSON library that supports defining the serialization depth. Ideally I would like a library that handles all primitive types and java.lang and the rest will be ...

18. How to serialize JSON object in java    stackoverflow.com

Hi I am using Voldemort to store my data. My key is a word and values are number of occurrence of the word and the URL. For example:

key :question
value: 10, www.stackoverflow.com
I ...

19. How can I serialize this JSON using Jackson annotations?    stackoverflow.com

I have the following JSON :

{ 
    fields : {
            "foo" : "foovalue",
     ...

20. how to prepare json file using gson library    stackoverflow.com

I have two plain pojo objects: Ex:

class person{
  private String name;
  private String id;
}
class address{
  private String homeaddress;
  private String officeaddress;
}
How to create JSON file with

21. json annotation to configure the serialized xml node's name of an object's property    stackoverflow.com

What i need to do is the following. i need using json, to serialize my object to xml as follows:

<employee>
   <name>Name</name>
   <id>the_database_id</id>
<employee>
my java code/bean is as follows:
public ...

22. Reading JSON file error    stackoverflow.com

I try to read JSON file with Java. The code is:

public static void main(String[] args) throws Exception {
    InputStream is = new FileInputStream("j.txt");
    String jsonTxt ...

23. How to serialize a class with an interface?    stackoverflow.com

I have never done much with serialization, but am trying to use Google's gson to serialize a Java object to a file. Here is an example of my issue:

public ...

24. Gson: How to exclude specific fields from Serialization without annotations    stackoverflow.com

I'm trying to learn Gson and I'm struggling with field exclusion. Here are my classes

public class Student {    
  private Long       ...

25. Json Deep serialize    stackoverflow.com

In a case where Person is a POJO having a List of "hobbies". Just trying to understand this statement to implement a deep serialize mechanism:

new JSONSerializer().include("hobbies").serialize( person ); 
Does ...

26. Jackson : field serialization format depending on other field value    stackoverflow.com

I have the following Java class and I want to serialize it to JSON using Jackson:

public class Event
   boolean allDay;
   Date start;
   Date end;

  ...

27. How to serialize/deserialize in both JSON and XML format in Java?    stackoverflow.com

Have a bunch of classes which I need to do serialize and deserialize from/to JSON/XML at the same time. Which library you recommend to this task?

28. Is there any way to convert Java object to JSON file    stackoverflow.com

Is there any way to convert Java object to JSON file ( I have array of objects and I want to export to JSON file, properties ) >

29. Is it possible to parse with JSON file using org.json in Java?    stackoverflow.com

How could be parse it for example?

{
    "392bc124":        {
            "ts": ...

30. How can I create this JsonObject using Gson API?    stackoverflow.com

I've been having trouble getting this json object to serialize/deserialize properly:

{
  series:[{
      data:[[long,int], ... ],
      label:String
  },
  ...
 ...

31. JSONDeserializer().serialize(ListJson)    stackoverflow.com

Hi i have jsonString ["ttt","uuuu"] how do i deserialize this in to list i have the following code

java.util.List pop = (java.util.List)new flexjson.JSONDeserializer().deserialize(ListJson);
i does not work can any one please help ...

32. Jackson JSON not serializing Joda DateTime correctly    stackoverflow.com

I have a Joda DateTime in an Order class:

public class Order {
    private DateTime creationTime;
    ...
}
I have initialized my mapper as follows:
mapper.configure(
    ...

33. How can I prevent Jackson from serializing a polymorphic type's annotation property?    stackoverflow.com

I have polymorphic types and deserializing from JSON to POJO works. I followed the documentation here, in fact. When serializing POJOs into JSON I'm getting an unwanted attribute, specifically ...

34. Iterating through multiple objects in JSON file    stackoverflow.com

I'm parsing a JSON file that I'm retrieving by accessing an API. Right now, I'm able to create an ArrayList of objects of my Offer class, but I'm only reading the ...

35. is this json file? and if yes, how can I read it back to java?    stackoverflow.com

Possible Duplicate:
A better Java JSON library?
Hi, I have a json file like this:
workloads = [
  {
    total: 5,
    ...

36. How to invoke another serializer from a custom Gson JsonSerializer?    stackoverflow.com

I have my custom class User:

class User {
    public String name;
    public int id;
    public Address address;
    public Timestamp ...

37. validating json file using java    stackoverflow.com

I am using classes which came from json.org. Using them, can someone suggest a sniplet of the code which would let one parse the input stream to see whether ...

38. How to force JSON-lib's JSONObject.put(..) to escape a string containing JSON?    stackoverflow.com

When using JSON-lib's JSONObject, how can I stop the put method from storing a String which contains JSON as JSON rather than as an escaped string? For instance:

JSONObject obj = new JSONObject();
obj.put("jsonStringValue","{\"hello\":\"world\"}");
obj.put("naturalStringValue", ...

39. Working with data .. Is separate bean needed to handle data retrieved from json file?    stackoverflow.com

Suppose you are working with some data, which comes from a JSON file. You read the file, parse it, make sure all needed variables are there and provide accessor methods to ...

40. How to keep fields sequence in Gson serialization    stackoverflow.com

Seems like Gson.toJson(Object object) generates JSON code with randomly spread fields of the object. Is there way to fix fields order somehow?


    public class Foo {
   ...

41. Java: serialize TreeModel, TableModel to JSON, and vice versa?    stackoverflow.com

On the client side, a user specified input creates a unique TreeModel and TableModel. This needs to be serialized to JSON for storage on MongoDB (stores JSON document directly). The JSON needs to ...

42. Best way to compare 2 JSON files in Java    stackoverflow.com

How would you suggest this task is approached? The challenge as i see it is in presenting diff information intelligently. Before i go reinventing the wheel, is there an accepted approach of ...

43. How can I control which instance variables are serialized when using Jackson JSON    stackoverflow.com

I am using JSON Jackson to convert from POJOs to JSON. I am using

mapper.writeValueAsString(s);
It is working fine. Problem is I dont't want to convert all class varaibles into JSON. Anyone ...

44. Jackson Serialization issue with CommonsMultipartFile    stackoverflow.com

I have a bean with CommonsMultipartFile type field like so:

public class Placement implements Serializable {

private static final long serialVersionUID = 1L;

private long placementId;
private String type;
private String placement;
private transient CommonsMultipartFile fileData;
I have ...

45. How to parse JSON File with json.org/java libraries?    stackoverflow.com

File f = new File("output.json");

FileReader fr = new FileReader(f);

BufferedReader br = new BufferedReader(fr);

StringBuffer sb = new StringBuffer();

String eachLine = br.readLine();

while (eachLine != null) {

   sb.append(eachLine);

   eachLine = ...

46. format json file with comma?    stackoverflow.com

I have a json file.

{"bla":"bla"}
{"bla":"bla"}
{"bla":"bla"}
{"bla":"bla"}
......
How can I format these into a valid json type, like:
[    
    {"bla":"bla"},
    {"bla":"bla"},
    {"bla":"bla"},
 ...

47. how to format no line break json file?    stackoverflow.com

This is a continue question by here. Now the problem is, there is no line break in each line. All data stick together, how can I do that? Like this:

{"bla":"bla"}{"bla":"bla"}{"bla":"bla"}{"bla":"bla"}{"bla":"bla"}{"bla":"bla"}.....
Thanks!

48. jackson IOException: Can not deserialize Class com.mycompany.models.Person$Address (of type non-static member class) as a Bean    stackoverflow.com

I have a class that looks like this:

public class Person {
    public class Address {
        private String line1;
    ...

49. How to merge two json files together in java    stackoverflow.com

I've finished my application, and when it finishes there will be two json files. I need to combine them in a different java class so i've tried something like this If ...

50. Invalid json representation of date    stackoverflow.com

My code:

import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
...
public void testDateSerializer() {
  final Date date = new Date();
  log.info("Today's date: " + date + " and date.getTime()=" + date.getTime());
  final JSONObject ...

51. What are bad use cases for Jackson/JSON?    stackoverflow.com

What would be characteristics or smells that would indicate it is a bad idea to use Jackson/JSON for a particular task or set of tasks? I'm still learning about this ...

52. How can I serialize a list of objects using flex json?    stackoverflow.com

I have a list of an object like follows

 List<ProductInfo> 
I want to serialize it using flex json so that it should like
 [{"product_id":"2","name":'stack"'},{"product_id":"2","name":"overflow"}]"
for deserializing from the above string into a ...

53. How do I use a custom Serializer with Jackson?    stackoverflow.com

I have two Java classes that I want to serialize to JSON using Jackson:

public class User {
    public final int id;
    public final String name;

 ...

54. Writing JSONObject into a file    stackoverflow.com

I'm using Play framework. I have a JSONObject which has a structure like the below (As in console it printed)

{
    "rows_map":{
        ...

55. Jackson and that dreaded IOException    stackoverflow.com

Jackson's ObjectMapper#readValue member throws three checked exceptions:

IOException 
JsonParseException 
JsonMappingException
JsonParseException and JsonMappingException extend IOException. I want to wrap the two aforementioned child classes and throw my own custom exceptions, yet, ...

56. Java JSON serialization - best practice    stackoverflow.com

I need to implement JSON serialization for some objects, and I've encountered a problem when it came to integration with generic collections. All serializable classes implement this interface (JSONObject comes from ...

57. How to traverse a JSON file?    stackoverflow.com

The JSON I have is mentioned below :-

{   head: {
    link: [],
    vars: [
      "CompanyName",
    ...

58. Convert a .json file to a JSONArray    stackoverflow.com

I used cURL to get some twitter feeds in the form of a json file ("twitter-feed.json"). I want to convert this json file to a JSONArray object. How do I do ...

59. jackson serialization, is there an annotation that indicates what sub-properties to use for a property?    stackoverflow.com

I'd like to see something like this

class User {
   @JsonMask({"name", "address"})
   private Company company;
   private String name;
   //...
}
class Company {
   private ...

60. Jackson processor for java bean to json\xml serialization    stackoverflow.com

Hi I am having a java bean and i need to serialize it to json. For this purpose i am using the jackson processor which is very powerful. But I also ...

61. Serializer - speed of Kryo, API/functionality like FlexJson    stackoverflow.com

Tile says it all. I love the functionality of FlexJson (clean API, backwards/forward data compatibility, ability to easily include/exclude data and transform it) but would love something as fast as ...

62. Invalid character while converting from JSON to XML using jsonlib    stackoverflow.com

I'm trying to convert a JSON string to XML using jsonlib in Java.

    JSONObject json = JSONObject.fromObject(jsonString); 
    XMLSerializer serializer = new XMLSerializer();
  ...

63. Field names in Jackson JSON Serialized List    stackoverflow.com

I have a class used to return lists of results that looks like :

public class TransactionResult {

    public List<MyObject> result;
    public boolean success;
   ...

64. Exception when serializing a stateless object with jackson Json    stackoverflow.com

I have been using the jackson implementation of the json protocol in my own little project, and it has gone just fine a while now until I decided (for the first ...

65. Using Jackson's @JsonTypeInfo with a custom serializer    stackoverflow.com

I'm running into a problem with Jackson where it does not respect the @JsonTypeInfo annotations when I use a custom serializer. The simplified example below does not require the custom ...

66. How to serialize Java properties to JSON    stackoverflow.com

Can I have JSON serialize properties (I mean Java bean getter and setter properties) of POJOs?

67. Fine grained serialization using json    coderanch.com

Hi All, I have a set of beans in the server side that needs to be rendered as a json object to the browser, for doin this we can use any of the open source libraraies like json, google json and many more but how can we have a fine grained control on the object properties. For ex: i have a ...

68. Including data in java code from a JSON file    forums.oracle.com

I have a big JSON file which I read into a javascript program from a file as a script. It contains a named array of generalized hash tables, ie: var arrayname = [ {...}, {...}, ... ]; in a file srcfile.js. I read it into my javascript as and then just use the array, without doing any parsing, etc. ...