com.abubusoft.kripton.map.BindMapHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kripton-core Show documentation
Show all versions of kripton-core Show documentation
Kripton Persistence Library - core module
package com.abubusoft.kripton.map;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.abubusoft.kripton.AbstractContext;
import com.abubusoft.kripton.exception.KriptonRuntimeException;
import com.abubusoft.kripton.persistence.JacksonWrapperParser;
import com.abubusoft.kripton.persistence.ParserWrapper;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
public abstract class BindMapHelper {
public static Map parseMap(AbstractContext context, ParserWrapper parserWrapper, Map map) {
switch (context.getSupportedFormat()) {
case XML:
throw (new KriptonRuntimeException(context.getSupportedFormat() + " context does not support parse direct map parsing"));
default:
JacksonWrapperParser wrapperParser = (JacksonWrapperParser) parserWrapper;
JsonParser parser = wrapperParser.jacksonParser;
map.clear();
return parseMap(context, parser, map, false);
}
}
/**
* Parse a
* @param context
* @param parser
* @param map
* @param skipRead
* @return
*/
static Map parseMap(AbstractContext context, JsonParser parser, Map map, boolean skipRead) {
try {
String key;
Object value;
if (!skipRead) {
parser.nextToken();
}
if (parser.currentToken() != JsonToken.START_OBJECT) {
throw (new KriptonRuntimeException("Invalid input format"));
}
skipRead = false;
do {
if (skipRead) {
key = parser.getCurrentName();
} else {
key = parser.nextFieldName();
skipRead = true;
}
JsonToken token = parser.nextToken();
switch (token) {
case START_ARRAY:
// parse array
value = parseList(context, parser, new ArrayList
© 2015 - 2025 Weber Informatics LLC | Privacy Policy