List of usage examples for com.fasterxml.jackson.databind.introspect AnnotatedMember fixAccess
public final void fixAccess()
From source file:org.jongo.marshall.jackson.JacksonObjectIdUpdater.java
public boolean mustGenerateObjectId(Object pojo) { for (BeanPropertyDefinition def : beanDescription(pojo.getClass()).findProperties()) { if (isIdProperty(def)) { AnnotatedMember accessor = def.getAccessor(); accessor.fixAccess(); return isObjectId(def) && accessor.getValue(pojo) == null; }/*from w ww . java 2 s .c o m*/ } return false; }
From source file:org.jongo.marshall.jackson.JacksonObjectIdUpdater.java
public Object getId(Object pojo) { BasicBeanDescription beanDescription = beanDescription(pojo.getClass()); for (BeanPropertyDefinition def : beanDescription.findProperties()) { if (isIdProperty(def)) { AnnotatedMember accessor = def.getAccessor(); accessor.fixAccess(); Object id = accessor.getValue(pojo); if (id instanceof String && isObjectId(def)) { return new ObjectId(id.toString()); } else { return id; }/*from w w w . jav a2s . c om*/ } } return null; }
From source file:org.jongo.marshall.jackson.JacksonObjectIdUpdater.java
public void setObjectId(Object target, ObjectId id) { for (BeanPropertyDefinition def : beanDescription(target.getClass()).findProperties()) { if (isIdProperty(def)) { AnnotatedMember accessor = def.getAccessor(); accessor.fixAccess(); if (accessor.getValue(target) != null) { throw new IllegalArgumentException("Unable to set objectid on class: " + target.getClass()); }/*from w w w.ja v a 2s. c o m*/ AnnotatedMember field = def.getField(); field.fixAccess(); Class<?> type = field.getRawType(); if (ObjectId.class.isAssignableFrom(type)) { field.setValue(target, id); } else if (type.equals(String.class) && isObjectId(def)) { field.setValue(target, id.toString()); } return; } } }