Skip to content

Commit 926c5ec

Browse files
committed
README.md 4
1 parent 05e7e41 commit 926c5ec

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed

README.md

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,31 @@ The key changes are:
2222
* Attributes are marked with a '@' prepended to the key
2323
* Content element is marked with a '#' prepended to the key
2424
* Since the json keeps order of the original xml elements it can be deserialized back to same xml.
25+
* Type inference is removed, every value is treated as string
2526

2627
#### Earlier version of JSON below refers to release version 20090211 or before.
2728

28-
An xml of format
29+
XML to JSON to XML conversion
2930
```java
30-
<root><person fname="samarjit" lname="samanta" >normal text</person></root>
31+
//This version 20121205 on wards
32+
<root><person fname="samarjit" lname="samanta" >normal text</person><version>1.0</version></root>
3133

32-
//will serialize to
33-
{"root":{"person":{"@fname":"samarjit","@lname":"samanta","#content":"normal text"}}}
34-
35-
//In earlier version it used to serialize to
36-
{"root":{"person":{"fname":"samarjit","lname":"samanta","content":"normal text"}}}
37-
```
38-
##JSON to XML Serialization
39-
40-
Since we have the attribute marked in the json, we can create back the exact xml
41-
```java
42-
//This version if input json is
43-
{"root":{"person":{"@fname":"samarjit","@lname":"samanta","#content":"normal text"}}}
44-
45-
//produces
46-
<root><person fname="samarjit" lname="samanta">normal text</person></root>
47-
48-
//Earlier version of JSON eg. release version 20090211 or before will produce
49-
{"root":{"person":{"content":"normal text","lname":"samanta","fname":"samarjit"}}}
50-
//produces
51-
<root><person>normal text<lname>samanta</lname><fname>samarjit</fname></person></root>
34+
//This version XML -> JSON
35+
{"root":{"person":{"@fname":"samarjit","@lname":"samanta","#content":"normal text"},"version":"1.0"}}
36+
//This version JSON -> XML
37+
<root><person fname="samarjit" lname="samanta">normal text</person><version>1.0</version></root>
38+
39+
40+
//## Earlier version json ##
41+
<root><person fname="samarjit" lname="samanta" >normal text</person><version>1.0</version></root>
42+
//Earlier version XML->JSON
43+
{"root":{"person":{"content":"normal text","lname":"samanta","fname":"samarjit"},"version":1}}
44+
//Earlier version JSON-> XML
45+
<root><person>normal text<lname>samanta</lname><fname>samarjit</fname></person><version>1.0</version></root>
46+
5247
```
5348
54-
Example of libraries that uses model as combination of Map<String,Object> and List<Object> and arbitrary java beans.
49+
####Example of libraries that uses model as combination of Map<String,Object> and List<Object> and arbitrary java beans.
5550

5651
### Freemarker
5752
```java
@@ -72,16 +67,16 @@ Example of libraries that uses model as combination of Map<String,Object> and Li
7267

7368
System.out.println(ret);
7469
```
75-
Result
70+
7671
```java
72+
Result
7773
//This version produces
7874
Hi jsss hello jhaldia your home is C:/Users/Samarjit
7975

8076
//Earlier version json:
8177
Hi jsss hello [ your home is C:/Users/Samarjit
8278
```
8379
84-
8580
### Ognl
8681
```java
8782
JSONObject jobj1 = new JSONObject();
@@ -92,9 +87,11 @@ Result
9287
Object obj2 = Ognl.getValue("someBean.sss",context);
9388
System.out.println(obj2);
9489
```
95-
Result
96-
This version produces
97-
```java
90+
91+
92+
```java
93+
Result
94+
//This version produces
9895
jhaldia
9996
dddd
10097

0 commit comments

Comments
 (0)