private void _throwNoDebugInfo(String className) { throw new JsonBindingException( "Class " + className + " has been compiled with no debug information, so we can not deduce constructor/method parameter names."); }
protected JsonBindingException couldNotSerialize(Throwable e) { return new JsonBindingException("Could not serialize property '" + name + "' from class " + declaringClass.getName(), e); }
public Trilean isCreator(Method method, Class<?> baseClass) { if (method.getAnnotation(JsonCreator.class) != null) { if (Modifier.isStatic(method.getModifiers())) return TRUE; throw new JsonBindingException("Method " + method.toGenericString() + " annotated with @Creator must be static!"); } return FALSE; }
public Trilean isCreator(Method method, Class<?> fromClass) { if (method.getAnnotation(JsonCreator.class) != null) { if (Modifier.isPublic(method.getModifiers()) && Modifier.isStatic(method.getModifiers())) return TRUE; throw new JsonBindingException("Method " + method.toGenericString() + " annotated with @JsonCreator must be static!"); } return FALSE; }
@Override public void serialize(T object, ObjectWriter writer, Context ctx) throws Exception { if (object == null) { throw new JsonBindingException("Serialization of null primitives is forbidden"); } else { wrapped.serialize(object, writer, ctx); } }
public Character deserialize(ObjectReader reader, Context ctx) { String str = reader.valueAsString(); if (str.length() > 1) throw new JsonBindingException( "Could not convert a string with length greater than 1 to a single char." ); return str.charAt(0); } }
protected JsonBindingException couldNotMutate(Exception e) { return new JsonBindingException("Could not mutate value of property named '" + name + "' using mutator " + signature(), e); }
@Override public synchronized XMLGregorianCalendar deserialize(ObjectReader reader, Context ctx) { GregorianCalendar cal = new GregorianCalendar(); try { cal.setTime(dateFormat.parse(reader.valueAsString())); } catch (ParseException e) { throw new JsonBindingException("Could not parse date " + reader.valueAsString(), e); } return dateFactory.newXMLGregorianCalendar(cal); }
@Override public synchronized XMLGregorianCalendar deserialize(ObjectReader reader, Context ctx) { GregorianCalendar cal = new GregorianCalendar(); try { cal.setTime(dateFormat.parse(reader.valueAsString())); } catch (ParseException e) { throw new JsonBindingException("Could not parse date " + reader.valueAsString(), e); } return dateFactory.newXMLGregorianCalendar(cal); }
@Override public Object deserialize(ObjectReader reader, Context ctx) throws Exception { Object value = converter.deserialize(reader, ctx); try { return adapter.unmarshal(value); } catch (Exception e) { throw new JsonBindingException("Could not unmarshal object using adapter " + adapter.getClass()); } }
@Override public void serialize(Object object, ObjectWriter writer, Context ctx) throws Exception { Object adaptedValue = null; try { adaptedValue = adapter.marshal(object); } catch (Exception e) { throw new JsonBindingException("Could not marshal object using adapter " + adapter.getClass()); } converter.serialize(adaptedValue, writer, ctx); } }
@Override public Object deserialize(ObjectReader reader, Context ctx) throws Exception { Object value = converter.deserialize(reader, ctx); try { return adapter.unmarshal(value); } catch (Exception e) { throw new JsonBindingException("Could not unmarshal object using adapter " + adapter.getClass()); } }
public URL deserialize(ObjectReader reader, Context ctx) { try { return new URL(reader.valueAsString()); } catch (MalformedURLException e) { throw new JsonBindingException("Can not deserializer <" + reader.valueAsString() + "> to URL."); } }
public URL deserialize(ObjectReader reader, Context ctx) { try { return new URL(reader.valueAsString()); } catch (MalformedURLException e) { throw new JsonBindingException("Can not deserializer <" + reader.valueAsString() + "> to URL."); } }
@Override public T deserialize(ObjectReader reader, Context ctx) throws Exception { if (ValueType.NULL == reader.getValueType()) { throw new JsonBindingException("Can not deserialize null to a primitive type"); } else { return wrapped.deserialize(reader, ctx); } } }
@Override public T deserialize(ObjectReader reader, Context ctx) throws Exception { if (ValueType.NULL == reader.getValueType()) { throw new JsonBindingException("Can not deserialize null to a primitive type"); } else { return wrapped.deserialize(reader, ctx); } } }
private void serializeNull(ObjectWriter writer) { try { writer.writeNull(); writer.flush(); } catch (Exception e) { throw new JsonBindingException("Could not serialize null value.", e); } }
private void serializeNull(ObjectWriter writer) { try { writer.writeNull(); writer.flush(); } catch (Exception e) { throw new JsonBindingException("Could not serialize null value.", e); } }
/** * Serializes this object and writes its representation to writer. As you are providing the * writer instance you also must ensure to call close on it when you are done. */ public void serialize(Object object, Type type, ObjectWriter writer, Context ctx) { Serializer<Object> ser = provideConverter(type); try { ser.serialize(object, writer, ctx); writer.flush(); } catch (Exception e) { throw new JsonBindingException("Failed to serialize object of type " + type, e); } }
public <T> T deserialize(GenericType<T> type, ObjectReader reader, Context ctx) { Deserializer<T> deser = provideConverter(type.getType()); try { return deser.deserialize(reader, ctx); } catch (Exception e) { throw new JsonBindingException("Could not deserialize to type " + type.getRawClass(), e); } }