JSONXML library is implemented trying to keep it as generic as possible.
It uses hierarchy of classes providing generalized functionality most of which are used both in parsing and in formatting process.
briefly these are:
Path - hierarchical structure elements may be accessed using simple path syntax: "name/name[idx]/name[idx]/name".
Path allows numeric and textual indexes and provides set of methods to simplify its analysis and conversions.
Formats - locale/time-zone specific formatter/parser of scalar values (numbers, dates). Provides possibility to try several format variants on parsing.
By overriding it context-specific (e.g. depending on path) conversions may be applied.
ObjectsRegistry - tool used to accumulate processed items and resolve cross-referencing problems.
ReflectiveBuilder - tool used to access Java object data reflectively on formatting and to restore objects on parsing.
Also it resolves problem of Map
Actual entry point to JSONXML library are basic classes:
Formatter - formatter implementation with shortcut methods for XML and JSON outputs.
Parser - shortcut methods to parse JSON and XML texts into Java objects.
Comparer - implementation of comparator of 2 java objects. Uses same structure scanning mechanisms as parser/formatter.
As example there're provided command-line tools:
converter - accepts file or URL, tries to parse it as XML or JSON and writes it to standard output in desired format (JSON, XML, Dump)
diff - accepts 2 input sources (file or URL, may be mixed), parses as XML or JSON and compares them. the difference is written to standard output in desired format.
When started to work with JSON I've used various parsers/formatters for Java.
Gradually I've gathered a number of limitations common to all or some of them.
As a result the following requirements to JSON parser/formatter (for Java) were formulated:
MUST implement specification published at json.org
MUST keep order of named object elements
MUST support reflection to save/restore Java objects
MUST accept Reader for input and Writer for output
MUST be licensed with minimal restrictions - Apache License 2.0 seems optimal.
MUST be distributed as single JAR and via maven repositories.
SHOULD allow "loose" syntax (e.g. use of quoted/unquoted names, double or single quoted strings)
SHOULD allow transparent conversion of JSON to XML and vice versa
SHOULD provide means of flexible comparison of structures
SHOULD support virtually any Java object by working around known "features" like stack overflow in collections with cross-references.
SHOULD allow easy and reliable customization via extensions at different code levels
SHOULD have no or minimal dependencies on 3rd party solutions (keep as "pure java")
Plans for future releases:
Extend reflection support to use known annotation "systems":
J2EE entities
xstream
???
Visual tool for structure browsing/comparison. (NOTE: preliminary experiments available as JSONViewer sub-project, see SVN)
Refactorying
Move most generic classes to separate library/project (like Path, Utilities, etc.)