Skip to content

Commit 37f6c39

Browse files
author
Andres Almiray
committed
Update docs
1 parent 98b6805 commit 37f6c39

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

README.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ image:https://img.shields.io/badge/donations-Patreon-f96854.svg?logo=patreon[lin
1616

1717
---
1818

19+
image::resources/images/json-lib.png[]
20+
1921
JSON-lib is a java library for transforming beans, maps, collections, java arrays and XML to JSON and back again to beans and DynaBeans.
2022

2123
Refer to the link:http://aalmiray.github.io/json-lib/[project guide, window="_blank"] for

resources/images/json-lib.png

7.82 KB
Loading
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
[[_faq_]]
3+
= FAQ
4+
5+
== If I use a LinkedHasMap to create a JSONObject the order is not preserved, why ?
6+
7+
The answer is in the JSON specification "An object is an unordered set of name/value pairs.
8+
An object begins with `{` (left brace) and ends with `}` (right brace).
9+
Each name is followed by `:` (colon) and the name/value pairs are separated by `,` (comma).".
10+
11+
JSONObject uses a HashMap for its properties representation because the order of its properties is not important.
12+
13+
<<_faq_,icon:arrow-up[] top>>
14+
15+
== Json-lib creates empty JSONObjects from my bean class, help me!
16+
17+
Json-lib uses the JavaBeans convention to inspect your beans and create JSONObjects.
18+
If the properties of your beans do not adhere to the convention, the resulting JSONObject will be empty or half empty.
19+
You must provide a read/write method pair for each property.
20+
21+
<<_faq_,icon:arrow-up[] top>>
22+
23+
== How do I configure Json-lib as a dependency with Maven2 ?
24+
25+
[source,xml,options="nowrap"]
26+
[subs="attributes,verbatim"]
27+
----
28+
<dependency>
29+
<groupId>{project-group}</groupId>
30+
<artifactId>{project-name}</artifactId>
31+
<version>{project-version}</version>
32+
</dependency>
33+
----
34+
35+
<<_faq_,icon:arrow-up[] top>>
36+
37+
== How can I transform a JSON string into a bean with an Enum property ?
38+
39+
You'll have to register a Morpher that can handle your Enum. Json-lib conveniently includes such a Morpher,
40+
so the only thing left to do is configure it and register the Morpher into the MorpherRegistry as follows
41+
`JSONUtils.getMorpherRegistry().registerMorpher(new EnumMorpher(MyEnum.class))`
42+
43+
This step is optional since Json-lib 2.2
44+
45+
<<_faq_,icon:arrow-up[] top>>
46+
47+
== How can I transform a simple value into a complex one when serializing back to Java ?
48+
49+
Perhaps you've come across a scenario where you'll want a JSON string like "{'id':1}" transformed back to a Java class,
50+
but the catch is that the id property is not a simple value but another class (a complex value), say a wrapper around a
51+
primitive long. If you try to serialize such a string back to Java you'll get a ClassCastException. The solution to this
52+
problem is registering a Morpher that can handle the input and transform it into an instance of the expected type, in
53+
this case the class of the id property.
54+
55+
<<_faq_,icon:arrow-up[] top>>
56+
57+
== Json-lib does not find my inner bean, help!
58+
59+
In order for Json-lib (in fact the PropertyDescriptors) to find and inspect your beans they have to be declared public,
60+
and all desired properties must have a public pair of reader/writer. The same applies to beans declared as inner classes
61+
(which by the way must also be declared static). Its a good practice to define each bean in its own file, but if you
62+
can't please make your inner beans public and static if possible.
63+
64+
<<_faq_,icon:arrow-up[] top>>
65+
66+
== I'd like to use XPath-like expressions with JSON, how do I do it ?
67+
68+
Use link:http://commons.apache.org/jxpath/[JXPath], which is a simple yet powerful project that enables XPath-like
69+
expressions to be used with java beans and maps.
70+
71+
<<_faq_,icon:arrow-up[] top>>

subprojects/guide/src/docs/asciidoc/index.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ include::{includedir}/usage.adoc[]
1414
include::{includedir}/configuration.adoc[]
1515
include::{includedir}/compatibility.adoc[]
1616
include::{includedir}/groovy.adoc[]
17+
include::{includedir}/faq.adoc[]
1718

1819
= Links
1920

subprojects/guide/src/docs/asciidoc/introduction.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,5 @@ and many others.
6969

7070
These properties make JSON an ideal data-interchange
7171
language.
72+
73+
NOTE: Documentation for older releases can be found at link:json-lib.sourceforge.net/[]

0 commit comments

Comments
 (0)