@Override public String toString() { return getClass().getName()+": "+getMessage(); }
public static JsonMappingException from(JsonParser jp, String msg, Throwable problem) { return new JsonMappingException(msg, jp.getTokenLocation(), problem); }
/** * Method that can be called to either create a new JsonMappingException * (if underlying exception is not a JsonMappingException), or augment * given exception with given path/reference information. */ public static JsonMappingException wrapWithPath(Throwable src, Reference ref) { JsonMappingException jme; if (src instanceof JsonMappingException) { jme = (JsonMappingException) src; } else { String msg = src.getMessage(); /* Related to [JACKSON-62], let's use a more meaningful placeholder * if all we have is null */ if (msg == null || msg.length() == 0) { msg = "(was "+src.getClass().getName()+")"; } jme = new JsonMappingException(msg, null, src); } jme.prependPath(ref); return jme; }
if (persistenceUnits.contains(",")) { Map<String, Map<String, String>> puProperties = new HashMap<String, Map<String, String>>(); puProperties = new ObjectMapper().readValue(externalProperties, puProperties.getClass()); emf = Persistence } else { Map<String, Object> puProperties = new HashMap<String, Object>(); puProperties = new ObjectMapper().readValue(externalProperties, puProperties.getClass()); emf = Persistence log.error(e.getMessage()); } catch (JsonMappingException e) { log.error(e.getMessage()); } catch (IOException e) { log.error(e.getMessage());
} else { if (mediaType.equalsIgnoreCase(MediaType.APPLICATION_JSON)) { ObjectMapper mapper = new ObjectMapper(); String output = null; output = mapper.writeValueAsString(result); } catch (JsonGenerationException e) { log.error(e.getMessage()); } catch (JsonMappingException e) { log.error(e.getMessage()); } catch (IOException e) { log.error(e.getMessage());
public String toJson(Object object) { ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(object); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
ObjectMapper objectMapper = new ObjectMapper(); final Timer.Context httpEventsIngestTimerContext = httpEventsIngestTimer.time(); try { request.content().writerIndex(), CharsetUtil.UTF_8); Event event = objectMapper.readValue(body, Event.class); Iterator<Event> iterator = objectMapper.reader(Event.class).readValues(body); if (iterator.hasNext()) { iterator.next(); DefaultHandler.sendResponse(ctx, request, response, HttpResponseStatus.OK); } catch (JsonMappingException e) { log.debug(String.format("Exception %s", e.toString())); response = String.format("Invalid Data: %s", e.getMessage()); DefaultHandler.sendErrorResponse(ctx, request, response, HttpResponseStatus.BAD_REQUEST); } catch (JsonParseException e){ log.debug(String.format("Exception %s", e.toString())); response = String.format("Invalid Data: %s", e.getMessage()); DefaultHandler.sendErrorResponse(ctx, request, response, HttpResponseStatus.BAD_REQUEST); } catch (InvalidDataException e) {
logger.debug("Received VC : " + serializedVC); VectorClockWrapper vcWrapper = mapper.readValue(serializedVC, VectorClockWrapper.class); } catch(JsonParseException e) { throw new VoldemortException("JSON parsing exception while trying to parse GET response " + e.getMessage(), e); } catch(JsonMappingException e) { throw new VoldemortException("JSON mapping exception while trying to parse GET response " + e.getMessage(), e); } catch(IOException e) {
public Object convertJSONToPOJO(String jsonString) { ObjectMapper mapper = new ObjectMapper(); Object pojo = null; try { pojo = mapper.readValue(jsonString, Object.class); } catch (JsonGenerationException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return pojo; }
public static <T> T readValueRefer(String jsonStr, Class<T> clazz) { try { return getInstance().readValue(jsonStr, new TypeReference<T>() { }); } catch (JsonParseException e) { e.printStackTrace(); } catch (JsonMappingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
@Override public void storeStatistics(ResourceStatistics stats, String location, Job job) throws IOException { Configuration conf = job.getConfiguration(); DataStorage storage = new HDataStorage(new Path(location).toUri(), ConfigurationUtil.toProperties(conf)); ElementDescriptor statFilePath = storage.asElement(location, statFileName); if(!statFilePath.exists() && stats != null) { try { new ObjectMapper().writeValue(statFilePath.create(), stats); } catch (JsonGenerationException e) { log.warn("Unable to write Resource Statistics for "+location); e.printStackTrace(); } catch (JsonMappingException e) { log.warn("Unable to write Resource Statistics for "+location); e.printStackTrace(); } } }
return _valueInstantiator.createUsingDelegate(_delegateDeserializer.deserialize(jp, ctxt)); if (_beanType.isAbstract()) { // for good measure, check this too throw JsonMappingException.from(jp, "Can not instantiate abstract type "+_beanType +" (need to add/enable type information?)"); throw new JsonMappingException("Can not deserialize Throwable of type "+_beanType +" without having a default contructor, a single-String-arg constructor; or explicit @JsonCreator"); int pendingIx = 0; for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { String propName = jp.getCurrentName(); SettableBeanProperty prop = _beanProperties.find(propName); jp.nextToken(); // to point to field value
JsonToken t = jp.getCurrentToken(); if (t == JsonToken.VALUE_STRING) { char[] buffer = jp.getTextCharacters(); int offset = jp.getTextOffset(); int len = jp.getTextLength(); String str = jp.getText(); if (str.length() != 1) { throw JsonMappingException.from(jp, "Can not convert a JSON String of length "+str.length()+" into a char element of char array");
throws IOException, JsonProcessingException JsonToken t = jp.getCurrentToken(); int lineNumber = -1; while ((t = jp.nextValue()) != JsonToken.END_OBJECT) { String propName = jp.getCurrentName(); if ("className".equals(propName)) { className = jp.getText(); lineNumber = jp.getIntValue(); } else { throw JsonMappingException.from(jp, "Non-numeric token ("+t+") for property 'lineNumber'");
public String toString() { try { return OBJECT_MAPPER.writeValueAsString(userFeatureMap); } catch (JsonGenerationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JsonMappingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
protected Object _unwrapAndDeserialize(JsonParser jp, JavaType rootType, DeserializationContext ctxt, JsonDeserializer<Object> deser) throws IOException, JsonParseException, JsonMappingException { SerializedString rootName = _deserializerProvider.findExpectedRootName(ctxt.getConfig(), rootType); if (jp.getCurrentToken() != JsonToken.START_OBJECT) { throw JsonMappingException.from(jp, "Current token not START_OBJECT (needed to unwrap root name '" +rootName+"'), but "+jp.getCurrentToken()); } if (jp.nextToken() != JsonToken.FIELD_NAME) { throw JsonMappingException.from(jp, "Current token not FIELD_NAME (to contain expected root name '" +rootName+"'), but "+jp.getCurrentToken()); } String actualName = jp.getCurrentName(); if (!rootName.getValue().equals(actualName)) { throw JsonMappingException.from(jp, "Root name '"+actualName+"' does not match expected ('"+rootName +"') for type "+rootType); } // ok, then move to value itself.... jp.nextToken(); Object result = deser.deserialize(jp, ctxt); // and last, verify that we now get matching END_OBJECT if (jp.nextToken() != JsonToken.END_OBJECT) { throw JsonMappingException.from(jp, "Current token not END_OBJECT (to match wrapper object with root name '" +rootName+"'), but "+jp.getCurrentToken()); } return result; }
private JsonNode decodeLineToJsonNode(String line) { try { return mapper.readTree(line); } catch (JsonParseException e) { e.printStackTrace(); return null; } catch (JsonMappingException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } }
@Override public final void deserializeAndSet(JsonParser jp, DeserializationContext ctxt, Object instance) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken(); if (t == JsonToken.VALUE_NULL) { /* Hmmh. Is this a problem? We won't be setting anything, so it's * equivalent of empty Collection/Map in this case */ return; } // Ok: then, need to fetch Collection/Map to modify: Object toModify; try { toModify = _getter.invoke(instance); } catch (Exception e) { _throwAsIOE(e); return; // never gets here } /* Note: null won't work, since we can't then inject anything * in. At least that's not good in common case. However, * theoretically the case where we get JSON null might * be compatible. If so, implementation could be changed. */ if (toModify == null) { throw new JsonMappingException("Problem deserializing 'setterless' property '"+getName()+"': get method returned null"); } _valueDeserializer.deserialize(jp, ctxt, toModify); }
elem = value[i]; if (elem == null) { provider.defaultSerializeNull(jgen); continue; ser.serialize(elem, jgen, provider); } else { ser.serializeWithType(elem, jgen, provider, typeSer); throw (Error) t; throw JsonMappingException.wrapWithPath(t, elem, i);
if (subclass != null) { try { type = (T) type.narrowBy(subclass); } catch (IllegalArgumentException iae) { throw new JsonMappingException("Failed to narrow type "+type+" with concrete-type annotation (value "+subclass.getName()+"), method '"+a.getName()+"': "+iae.getMessage(), null, iae); if (type.isContainerType()) { Class<?> keyClass = intr.findDeserializationKeyType(a, type.getKeyType(), propName); if (keyClass != null) { throw new JsonMappingException("Illegal key-type annotation: type "+type+" is not a Map(-like) type"); throw new JsonMappingException("Failed to narrow key type "+type+" with key-type annotation ("+keyClass.getName()+"): "+iae.getMessage(), null, iae); type = (T) type.narrowContentsBy(cc); } catch (IllegalArgumentException iae) { throw new JsonMappingException("Failed to narrow content type "+type+" with content-type annotation ("+cc.getName()+"): "+iae.getMessage(), null, iae);