public ReadableObjectId findObjectId(Object paramObject, ObjectIdGenerator<?> paramObjectIdGenerator) { ObjectIdGenerator.IdKey localIdKey = paramObjectIdGenerator.key(paramObject); if (this._objectIds == null) { this._objectIds = new LinkedHashMap(); } else { ReadableObjectId localReadableObjectId1 = (ReadableObjectId)this._objectIds.get(localIdKey); if (localReadableObjectId1 != null) return localReadableObjectId1; } ReadableObjectId localReadableObjectId2 = new ReadableObjectId(paramObject); this._objectIds.put(localIdKey, localReadableObjectId2); return localReadableObjectId2; }
/** * */ @Override public E resolveId(IdKey idKey) { try { if (idKey.key instanceof Integer) { final Integer id = (Integer) idKey.key; // we only "load" the entity to follow a lazy approach, i.e. // requests to the database will only be queried if any properties // of the entity will (later) be accessed (which may already // the case when jackson is doing some magic) return service.loadById(id); } else { throw new Exception("ID is not of type Integer."); } } catch (Exception e) { LOG.error("Could not resolve object by ID: " + e.getMessage()); return null; } }
@Override public void bindItem(IdKey id, Object ob) { if (_items == null) { _items = new HashMap<ObjectIdGenerator.IdKey,Object>(); } else if (_items.containsKey(id)) { throw new IllegalStateException("Already had POJO for id (" + id.key.getClass().getName() + ") [" + id + "]"); } _items.put(id, ob); }
@Override public void bindItem(IdKey id, Object ob) { if (_items == null) { _items = new HashMap<IdKey,Object>(); } else if (_items.containsKey(id)) { throw new IllegalStateException("Already had POJO for id (" + id.key.getClass().getName() + ") [" + id + "]"); } _items.put(id, ob); }
/** * <p>addObjectId</p> * * @param id a {@link com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey} object. * @param instance a {@link Object} object. */ @Override public void addObjectId(IdKey id, Object instance) { if (null == idToObject) { idToObject = new HashMap<IdKey, Object>(); } idToObject.put(id, instance); }
/** * <p>getObjectWithId</p> * * @param id a {@link com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey} object. * @return a {@link Object} object. */ @Override public Object getObjectWithId(IdKey id) { if (null != idToObject) { return idToObject.get(id); } return null; }
public Map<IdKey, Object> getItemMap() { if(_items == null) { return Collections.emptyMap(); } else { return _items; } }
public static void registerTokens(ObjectMapper mapper, List<String> tokens) { TokenList list = new TokenList(); list.setTokens(tokens); TokensIdGenerator generator = MapperFactory.getTokenIdGenerator(mapper); TokensIdResolver resolver = MapperFactory.getTokenIdResolver(mapper); Integer keyAsId = generator.generateId(list); IdKey id = generator.key(keyAsId); resolver.bindItem(id, list); }
public static void registerTokens(ObjectMapper mapper, Integer id, List<String> tokens) { TokenList list = new TokenList(); list.setTokens(tokens); TokensIdGenerator generator = MapperFactory.getTokenIdGenerator(mapper); TokensIdResolver resolver = MapperFactory.getTokenIdResolver(mapper); if(!generator.isRegistered(id)) { generator.register(id, list); } IdKey idKey = generator.key(id); if(!resolver.isRegistered(idKey)) { resolver.bindItem(idKey, list); } }
/** * <p>addObjectId</p> * * @param id a {@link com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey} object. * @param instance a {@link java.lang.Object} object. */ public void addObjectId( IdKey id, Object instance ) { if ( null == idToObject ) { idToObject = new HashMap<IdKey, Object>(); } idToObject.put( id, instance ); }
@Override public Object resolveId(IdKey id) { return ImmutableByid.builder() .id(id.key.toString()) .build(); }
@Override public Object resolveId(IdKey id) { return (_items == null) ? null : _items.get(id); }
/** * {@inheritDoc} */ @Override public IdKey newIdKey(Object id) { return new IdKey(type, scope, id); }
public boolean isRegistered(IdKey id) { return getItemMap().containsKey(id); }
public Set<Entry<IdKey, Object>> getItems() { return getItemMap().entrySet(); }
public ObjectIdGenerator.IdKey key(Object paramObject) { return new ObjectIdGenerator.IdKey(getClass(), this._scope, paramObject); }
/** * */ @Override public void bindItem(IdKey id, Object ob) { super.bindItem(id, ob); }
/** {@inheritDoc} */ @Override public IdKey newIdKey( Object id ) { return new IdKey( type, scope, id ); }
/** * <p>getObjectWithId</p> * * @param id a {@link com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey} object. * * @return a {@link java.lang.Object} object. */ public Object getObjectWithId( IdKey id ) { if ( null != idToObject ) { return idToObject.get( id ); } return null; }
/** * Method called when a POJO is deserialized and has an Object Identifier. * Method exists so that implementation can keep track of existing object in * JSON stream that could be useful for further resolution. * * @param id The Object Identifer * @param pojo The POJO associated to that Identifier */ void bindItem(IdKey id, Object pojo);
/** * Method called when deserialization encounters the given Object Identifier * and requires the POJO associated with it. * * @param id The Object Identifier * @return The POJO, or null if unable to resolve. */ Object resolveId(IdKey id);
/** * <p>newIdKey</p> * * @param id Identifier * @return a new {@link IdKey} */ IdKey newIdKey(Object id);
/** * <p>newIdKey</p> * * @param id Identifier * @return a new {@link IdKey} */ IdKey newIdKey( Object id );