Created
April 1, 2015 03:48
-
-
Save AndyFaibishenko/3d27c78613b4880e41f0 to your computer and use it in GitHub Desktop.
convertFieldMapToJSON method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void convertFieldMapToJSON(DataDictionary dataDictionary, | |
FieldMap fieldmap, ObjectNode node) throws FieldNotFound { | |
// First process the "regular" fields. | |
Iterator<Field<?>> fieldIterator = fieldmap.iterator(); | |
while (fieldIterator.hasNext()) { | |
Field field = (Field) fieldIterator.next(); | |
String value = fieldmap.getString(field.getTag()); | |
if (!isGroupCountField(dataDictionary, field)) { | |
node.put(String.valueOf(field.getTag()), value); | |
} | |
} | |
// Now process the repeating groups | |
Iterator groupsKeys = fieldmap.groupKeyIterator(); | |
while (groupsKeys.hasNext()) { | |
int groupCountTag = ((Integer) groupsKeys.next()).intValue(); | |
Group group = new Group(groupCountTag, 0); | |
ArrayNode repeatingGroup = node.putArray(String.valueOf(groupCountTag)); | |
int i = 1; | |
while (fieldmap.hasGroup(i, groupCountTag)) { | |
fieldmap.getGroup(i, group); | |
ObjectNode groupNode = repeatingGroup.addObject(); | |
// call this method recursively to process each repeating group to handle | |
// nested repeating groups | |
convertFieldMapToJSON(dataDictionary, group, groupNode); | |
i++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment