This library converts a fixed-width data stream into its JSON equivalent using a Copybook to define both structures.
git clone https://github.com/devstopfix/cb2java.git
cd cb2java
mvn install
cd ..
git clone https://github.com/devstopfix/cb2json.git
cd cb2json
mvn install
Include the JAR file in your Java project pom.xml:
<dependency>
<groupId>net.devstopfix.cb2json</groupId>
<artifactId>cb2json</artifactId>
<version>1.1</version>
</dependency>
or your Leiningen project.clj:
[net.devstopfix.cb2json/cb2json "1.1"]
- Create an instance of the
Copybook
class using theCopybookParser
object or theCopybooks
helper - Use the functions of
CB2JSON
, one parameter will be yourCopybook
, the others will be your input and output streams
This library is currently in the first of three versions. The functionality remains the same but the implementation details and performance vary:
A simple prototype that makes many internal data conversions:
- Uses a fork of the cb2java library to parse a Copybook into a tree of cb2java Data objects
- Convert the Data tree into a POJO tree of Maps and Lists using toMap
- Convert the POJO tree to JSON using Jacksons ObjectMapper
Possible improvements:
- skip the conversion from Data to POJOs
- write the data directly to the Jackson streaming API
- Make one pass over the Copybook stream, do not generate the intermediate cb2java Data objects but write JSON directly to the output stream using Jackson streaming API