@Override public String toString() { return getClass().getName()+": "+getMessage(); }
@Override public Response toResponse(JsonMappingException exception) { return Response.status(Response.Status.BAD_REQUEST) .entity(ImmutableMap.of( "error", exception.getMessage() == null ? "unknown json mapping exception" : exception.getMessage() )) .build(); } }
protected <R> R _handleMappingException(JsonMappingException e) { throw new RuntimeJsonMappingException(e.getMessage(), e); }
@Override public String getMessage() { String msg = super.getMessage(); if (_unresolvedIds == null) { return msg; } StringBuilder sb = new StringBuilder(msg); Iterator<UnresolvedId> iterator = _unresolvedIds.iterator(); while (iterator.hasNext()) { UnresolvedId unresolvedId = iterator.next(); sb.append(unresolvedId.toString()); if (iterator.hasNext()) { sb.append(", "); } } sb.append('.'); return sb.toString(); } }
@Override public T next() { try { return nextValue(); } catch (JsonMappingException e) { throw new RuntimeJsonMappingException(e.getMessage(), e); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } }
/** * bean、array、List、Map --> json * * @param obj * @return json string * @throws Exception */ public static String writeValueAsString(Object obj) { try { return getInstance().writeValueAsString(obj); } catch (JsonGenerationException e) { logger.error(e.getMessage(), e); } catch (JsonMappingException e) { logger.error(e.getMessage(), e); } catch (IOException e) { logger.error(e.getMessage(), e); } return null; }
/** * string --> bean、Map、List(array) * * @param jsonStr * @param clazz * @return obj * @throws Exception */ public static <T> T readValue(String jsonStr, Class<T> clazz) { try { return getInstance().readValue(jsonStr, clazz); } catch (JsonParseException e) { logger.error(e.getMessage(), e); } catch (JsonMappingException e) { logger.error(e.getMessage(), e); } catch (IOException e) { logger.error(e.getMessage(), e); } return null; }
/** * string --> List<Bean>... * * @param jsonStr * @param parametrized * @param parameterClasses * @param <T> * @return */ public static <T> T readValue(String jsonStr, Class<?> parametrized, Class<?>... parameterClasses) { try { JavaType javaType = getInstance().getTypeFactory().constructParametricType(parametrized, parameterClasses); return getInstance().readValue(jsonStr, javaType); } catch (JsonParseException e) { logger.error(e.getMessage(), e); } catch (JsonMappingException e) { logger.error(e.getMessage(), e); } catch (IOException e) { logger.error(e.getMessage(), e); } return null; }
@Override public Iterable<T> apply(final InputStream input) { try (InputStream actual = input) { String text = CharStreams.toString(new InputStreamReader(actual)); return DEFAULT_MAPPER.readValue(text, type); } catch (UnrecognizedPropertyException e) { logger.info("Unrecognized field: {}", e.getMessage()); throw new MocoException(format("Unrecognized field [ %s ], please check!", e.getPropertyName())); } catch (JsonMappingException e) { logger.info("{} {}", e.getMessage(), e.getPathReference()); throw new MocoException(e); } catch (IOException e) { throw new MocoException(e); } } };
private DataModelDesc deserializeDataModelDesc(ModelRequest modelRequest) { DataModelDesc desc = null; try { logger.debug("Saving MODEL " + modelRequest.getModelDescData()); desc = JsonUtil.readValue(modelRequest.getModelDescData(), DataModelDesc.class); } catch (JsonParseException e) { logger.error("The data model definition is not valid.", e); updateRequest(modelRequest, false, e.getMessage()); } catch (JsonMappingException e) { logger.error("The data model definition is not valid.", e); updateRequest(modelRequest, false, e.getMessage()); } catch (IOException e) { logger.error("Failed to deal with the request.", e); throw new InternalErrorException("Failed to deal with the request:" + e.getMessage(), e); } return desc; }
private CubeDesc deserializeCubeDesc(CubeRequest cubeRequest) { CubeDesc desc = null; try { logger.debug("Saving cube " + cubeRequest.getCubeDescData()); desc = JsonUtil.readValue(cubeRequest.getCubeDescData(), CubeDesc.class); } catch (JsonParseException e) { logger.error("The cube definition is not valid.", e); updateRequest(cubeRequest, false, e.getMessage()); } catch (JsonMappingException e) { logger.error("The cube definition is not valid.", e); updateRequest(cubeRequest, false, e.getMessage()); } catch (IOException e) { logger.error("Failed to deal with the request.", e); throw new InternalErrorException("Failed to deal with the request:" + e.getMessage(), e); } return desc; }
private KafkaConfig deserializeKafkaSchemalDesc(StreamingRequest streamingRequest) { KafkaConfig desc = null; try { logger.debug("Saving KafkaConfig " + streamingRequest.getKafkaConfig()); desc = JsonUtil.readValue(streamingRequest.getKafkaConfig(), KafkaConfig.class); updateRequest(streamingRequest, true, null); } catch (JsonParseException e) { logger.error("The KafkaConfig definition is invalid.", e); updateRequest(streamingRequest, false, e.getMessage()); } catch (JsonMappingException e) { logger.error("The data KafkaConfig definition is invalid.", e); updateRequest(streamingRequest, false, e.getMessage()); } catch (IOException e) { logger.error("Failed to deal with the request.", e); throw new InternalErrorException("Failed to deal with the request:" + e.getMessage(), e); } return desc; }
private StreamingConfig deserializeSchemalDesc(StreamingRequest streamingRequest) { StreamingConfig desc = null; try { logger.debug("Saving StreamingConfig " + streamingRequest.getStreamingConfig()); desc = JsonUtil.readValue(streamingRequest.getStreamingConfig(), StreamingConfig.class); updateRequest(streamingRequest, true, null); } catch (JsonParseException e) { logger.error("The StreamingConfig definition is invalid.", e); updateRequest(streamingRequest, false, e.getMessage()); } catch (JsonMappingException e) { logger.error("The data StreamingConfig definition is invalid.", e); updateRequest(streamingRequest, false, e.getMessage()); } catch (IOException e) { logger.error("Failed to deal with the request.", e); throw new InternalErrorException("Failed to deal with the request:" + e.getMessage(), e); } return desc; }
} catch (JsonMappingException e) { throw ConfigurationParsingException.builder("Failed to parse configuration") .setDetail(e.getMessage()) .setFieldPath(e.getPath()) .setLocation(e.getLocation())
private TableDesc deserializeTableDesc(StreamingRequest streamingRequest) { TableDesc desc = null; try { logger.debug("Saving TableDesc " + streamingRequest.getTableData()); desc = JsonUtil.readValue(streamingRequest.getTableData(), TableDesc.class); updateRequest(streamingRequest, true, null); } catch (JsonParseException e) { logger.error("The TableDesc definition is invalid.", e); updateRequest(streamingRequest, false, e.getMessage()); } catch (JsonMappingException e) { logger.error("The data TableDesc definition is invalid.", e); updateRequest(streamingRequest, false, e.getMessage()); } catch (IOException e) { logger.error("Failed to deal with the request.", e); throw new InternalErrorException("Failed to deal with the request:" + e.getMessage(), e); } if (null != desc) { String[] dbTable = HadoopUtil.parseHiveTableName(desc.getName()); desc.setName(dbTable[1]); desc.setDatabase(dbTable[0]); desc.getIdentity(); } return desc; }
@Override public Response toResponse(JsonMappingException exception) { return Response.status(Response.Status.BAD_REQUEST).entity(exception.getMessage()).type("text/plain").build(); } }
public static <T> T readValueRefer(String jsonStr, TypeReference typeReference) { try { return getInstance().readValue(jsonStr, typeReference); // new TypeReference<T>() { } } catch (JsonParseException e) { logger.error(e.getMessage(), e); } catch (JsonMappingException e) { logger.error(e.getMessage(), e); } catch (IOException e) { logger.error(e.getMessage(), e); } return null; }
/** * bean、array、List、Map --> json * * @param obj * @return json string * @throws Exception */ public static String writeValueAsString(Object obj) { try { return getInstance().writeValueAsString(obj); } catch (JsonGenerationException e) { logger.error(e.getMessage(), e); } catch (JsonMappingException e) { logger.error(e.getMessage(), e); } catch (IOException e) { logger.error(e.getMessage(), e); } return null; }
/** * string --> bean、Map、List(array) * * @param jsonStr * @param clazz * @return obj * @throws Exception */ public static <T> T readValue(String jsonStr, Class<T> clazz) { try { return getInstance().readValue(jsonStr, clazz); } catch (JsonParseException e) { logger.error(e.getMessage(), e); } catch (JsonMappingException e) { logger.error(e.getMessage(), e); } catch (IOException e) { logger.error(e.getMessage(), e); } return null; } public static <T> T readValueRefer(String jsonStr, TypeReference typeReference) {
type = intr.refineSerializationType(config, beanDesc.getClassInfo(), origType); } catch (JsonMappingException e) { return prov.reportBadTypeDefinition(beanDesc, e.getMessage());