本文整理汇总了Java中com.fasterxml.jackson.databind.RuntimeJsonMappingException类的典型用法代码示例。如果您正苦于以下问题:Java RuntimeJsonMappingException类的具体用法?Java RuntimeJsonMappingException怎么用?Java RuntimeJsonMappingException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RuntimeJsonMappingException类属于com.fasterxml.jackson.databind包,在下文中一共展示了RuntimeJsonMappingException类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNestedOrderedOrGetEmpty
import com.fasterxml.jackson.databind.RuntimeJsonMappingException; //导入依赖的package包/类
public Config getNestedOrderedOrGetEmpty(String key)
{
JsonNode value = getNode(key);
if (value == null) {
value = newObjectNode();
}
else if (value.isArray()) {
Config config = new Config(mapper);
Iterator<JsonNode> ite = ((ArrayNode) value).elements();
while (ite.hasNext()) {
JsonNode nested = ite.next();
if (!(nested instanceof ObjectNode)) {
throw new RuntimeJsonMappingException("Expected object but got "+nested);
}
// here assumes config is an order-preserving map
config.setAll(new Config(mapper, (ObjectNode) nested));
}
return config;
}
else if (!value.isObject()) {
throw new ConfigException("Parameter '"+key+"' must be an object or array of objects");
}
return new Config(mapper, (ObjectNode) value);
}
示例2: decode
import com.fasterxml.jackson.databind.RuntimeJsonMappingException; //导入依赖的package包/类
@Override
public Object decode(Response response, Type type) throws IOException, FeignException {
if (response.body() == null) {
return null;
}
Reader reader = response.body().asReader();
if (!reader.markSupported()) {
reader = new BufferedReader(reader, 1);
}
try {
// Read the first byte to see if we have any data
reader.mark(1);
if (reader.read() == -1) {
return null; // Eagerly returning null avoids "No content to map due to end-of-input"
}
reader.reset();
return mapper.readValue(reader, mapper.constructType(type));
} catch (RuntimeJsonMappingException e) {
Throwable cause = e.getCause();
if (cause != null && cause instanceof IOException) {
throw IOException.class.cast(cause);
}
throw e;
}
}
示例3: read
import com.fasterxml.jackson.databind.RuntimeJsonMappingException; //导入依赖的package包/类
@Override
public Object read() throws IOException {
if (closed) {
throw new IOException("The parser is closed");
}
try {
Object value = null;
switch (mode) {
case ARRAY_OBJECTS:
value = readObjectFromArray();
break;
case MULTIPLE_OBJECTS:
value = readObjectFromStream();
break;
}
return value;
} catch (RuntimeJsonMappingException ex) {
throw new JsonParseException(ex.toString(), jsonParser.getTokenLocation(), ex);
}
}
示例4: decode
import com.fasterxml.jackson.databind.RuntimeJsonMappingException; //导入依赖的package包/类
@Override
public Object decode(Response response, Type type) throws IOException {
if (response.status() == 404) return Util.emptyValueOf(type);
if (response.body() == null) return null;
Reader reader = response.body().asReader();
if (!reader.markSupported()) {
reader = new BufferedReader(reader, 1);
}
try {
// Read the first byte to see if we have any data
reader.mark(1);
if (reader.read() == -1) {
return null; // Eagerly returning null avoids "No content to map due to end-of-input"
}
reader.reset();
return mapper.readValue(reader, mapper.constructType(type));
} catch (RuntimeJsonMappingException e) {
if (e.getCause() != null && e.getCause() instanceof IOException) {
throw IOException.class.cast(e.getCause());
}
throw e;
}
}
示例5: decode
import com.fasterxml.jackson.databind.RuntimeJsonMappingException; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Object decode(final Response response, final Type type) throws IOException {
if (
response.status() == HttpURLConnection.HTTP_NO_CONTENT
|| response.body() == null
|| (response.body().length() != null && response.body().length() == 0)
) {
return null;
}
try (final Reader reader = response.body().asReader()) {
return this.mapper.readValue(reader, this.mapper.constructType(type));
} catch (final JsonMappingException jme) {
// The case where for whatever reason (most likely bad design) where the server returned OK and
// trying to de-serialize the content had no content (e.g. the return status should have been no-content)
if (response.status() == HttpURLConnection.HTTP_OK
&& jme.getMessage().startsWith(NO_CONTENT_MESSAGE)) {
return null;
}
throw jme;
} catch (final RuntimeJsonMappingException e) {
if (e.getCause() != null && e.getCause() instanceof IOException) {
throw IOException.class.cast(e.getCause());
}
throw e;
}
}
示例6: normalizeValidateObjectNode
import com.fasterxml.jackson.databind.RuntimeJsonMappingException; //导入依赖的package包/类
private ObjectNode normalizeValidateObjectNode(Object object)
throws IOException
{
JsonNode node = treeObjectMapper.readTree(treeObjectMapper.writeValueAsString(object));
if (!node.isObject()) {
throw new RuntimeJsonMappingException("Expected object to load Config but got "+node);
}
return (ObjectNode) node;
}
示例7: deserializeFromJackson
import com.fasterxml.jackson.databind.RuntimeJsonMappingException; //导入依赖的package包/类
@JsonCreator
public static Config deserializeFromJackson(@JacksonInject ObjectMapper mapper, JsonNode object)
{
if (!object.isObject()) {
throw new RuntimeJsonMappingException("Expected object but got "+object);
}
return new Config(mapper, (ObjectNode) object);
}
示例8: merge
import com.fasterxml.jackson.databind.RuntimeJsonMappingException; //导入依赖的package包/类
/**
* Merges the current application configuration with the provided one.
*
* @param config The configuration to retrieve values from.
*/
public void merge(Map<String, String> config) {
String languageCode = getString(config, "language");
Locale theLanguage;
if (languageCode != null) {
theLanguage = Locale.forLanguageTag(languageCode);
} else {
theLanguage = Locale.getDefault();
}
setLanguage(theLanguage);
pageSizeForText = getInt(config, "paging.textPageSize");
pageSizeForImages = getInt(config, "paging.imagePageSize");
pageSizeForAlbums = getInt(config, "paging.albumPageSize");
thumbnailWidth = getInt(config, "thumbnail.width");
thumbnailHeight = getInt(config, "thumbnail.height");
// Load the header links as JSON data
headerLinksSpec = getString(config, "header.quickLinks", "[]");
JsonFactory jsonFactory = new JsonFactory();
ObjectMapper jsonMapper = new ObjectMapper(jsonFactory);
CollectionType jsonType = jsonMapper.getTypeFactory().constructCollectionType(ArrayList.class,
HeaderLink.class);
List<HeaderLink> links = new ArrayList<>();
try {
LOGGER.debug("Header links: {}", headerLinksSpec);
JsonParser jsonParser = jsonFactory.createParser(headerLinksSpec);
links = jsonMapper.<List<HeaderLink>> readValue(jsonParser, jsonType);
} catch (RuntimeJsonMappingException | IOException e) {
LOGGER.warn("Failed to load the header configuration", e);
}
headerLinks = links;
}