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 ObjectIdGenerator<?> objectIdGeneratorInstance(Annotated annotated, ObjectIdInfo objectIdInfo) throws JsonMappingException { Class<?> implClass = objectIdInfo.getGeneratorType(); HandlerInstantiator hi = _config.getHandlerInstantiator(); ObjectIdGenerator<?> gen; if (hi != null) { gen = hi.objectIdGeneratorInstance(_config, annotated, implClass); } else { gen = (ObjectIdGenerator<?>) ClassUtil.createInstance(implClass, _config.canOverrideAccessModifiers()); } return gen.forScope(objectIdInfo.getScope()); }
/** * We must override this method, to prevent errors when scopes are the same, * but underlying class (on which to access property) is different. */ @Override public boolean canUseFor(ObjectIdGenerator<?> gen) { if (gen.getClass() == getClass()) { PropertyBasedObjectIdGenerator other = (PropertyBasedObjectIdGenerator) gen; if (other.getScope() == _scope) { /* 26-Jul-2012, tatu: This is actually not enough, because the property * accessor within BeanPropertyWriter won't work for other property fields * (see [https://github.com/FasterXML/jackson-module-jaxb-annotations/issues/9] * for details). * So we need to verify that underlying property is actually the same. */ return (other._property == _property); } } return false; }
@Override public Object resolveId(final ObjectIdGenerator.IdKey id) { Object entity = repository.findOne((Long) id.key); if (entity == null) { throw new BusinessException(ErrorConstants.ERR_NOTFOUND, "Can not resolve XmEntity by ID: " + id.key); } return entity; }
@Override public Object resolveId(final ObjectIdGenerator.IdKey id) { Object entity = repository.findOne((Long) id.key); if (entity == null) { throw new BusinessException(ErrorConstants.ERR_NOTFOUND, "Can not resolve Calendar by ID: " + id.key); } return entity; }
/** * Used by generated {@link AbstractBeanJsonSerializer} * * @param generator instance of generator to add */ @Override @SuppressWarnings("UnusedDeclaration") public void addGenerator(ObjectIdGenerator<?> generator) { if (null == generators) { generators = new ArrayList<ObjectIdGenerator<?>>(); } generators.add(generator); }
/** * Used by generated {@link AbstractBeanJsonSerializer} * * @param gen generator used to find equivalent generator * @param <T> a T object. * @return a {@link com.fasterxml.jackson.annotation.ObjectIdGenerator} object. */ @Override @SuppressWarnings({"UnusedDeclaration", "unchecked"}) public <T> ObjectIdGenerator<T> findObjectIdGenerator(ObjectIdGenerator<T> gen) { if (null != generators) { for (ObjectIdGenerator<?> generator : generators) { if (generator.canUseFor(gen)) { return (ObjectIdGenerator<T>) generator; } } } return null; }
@Override public ObjectIdGenerator<?> objectIdGeneratorInstance(MapperConfig<?> config, Annotated annotated, Class<?> implClass) { if(annotated.getRawType().equals(TokenList.class)) { return tokenIdGenerator; } else { return null; } }
protected ObjectIdWriter constructObjectIdHandler(SerializerProvider paramSerializerProvider, BeanDescription paramBeanDescription, List<BeanPropertyWriter> paramList) { ObjectIdInfo localObjectIdInfo = paramBeanDescription.getObjectIdInfo(); if (localObjectIdInfo == null) return null; Class localClass = localObjectIdInfo.getGeneratorType(); if (localClass == ObjectIdGenerators.PropertyGenerator.class) { String str = localObjectIdInfo.getPropertyName(); int i = 0; int j = paramList.size(); BeanPropertyWriter localBeanPropertyWriter; while (true) { if (i == j) throw new IllegalArgumentException("Invalid Object Id definition for " + paramBeanDescription.getBeanClass().getName() + ": can not find property with name '" + str + "'"); localBeanPropertyWriter = (BeanPropertyWriter)paramList.get(i); if (str.equals(localBeanPropertyWriter.getName())) { if (i <= 0) break; paramList.remove(i); paramList.add(0, localBeanPropertyWriter); break; } i++; } return ObjectIdWriter.construct(localBeanPropertyWriter.getType(), null, new PropertyBasedObjectIdGenerator(localObjectIdInfo, localBeanPropertyWriter), localObjectIdInfo.getAlwaysAsId()); } JavaType localJavaType1 = paramSerializerProvider.constructType(localClass); JavaType localJavaType2 = paramSerializerProvider.getTypeFactory().findTypeParameters(localJavaType1, ObjectIdGenerator.class)[0]; ObjectIdGenerator localObjectIdGenerator = paramSerializerProvider.objectIdGeneratorInstance(paramBeanDescription.getClassInfo(), localObjectIdInfo); return ObjectIdWriter.construct(localJavaType2, localObjectIdInfo.getPropertyName(), localObjectIdGenerator, localObjectIdInfo.getAlwaysAsId()); }
protected ObjectIdWriter(JavaType paramJavaType, SerializedString paramSerializedString, ObjectIdGenerator<?> paramObjectIdGenerator, JsonSerializer<?> paramJsonSerializer, boolean paramBoolean) { this.idType = paramJavaType; this.propertyName = paramSerializedString; this.generator = paramObjectIdGenerator; this.serializer = paramJsonSerializer; this.alwaysAsId = paramBoolean; }
public boolean canUseFor(ObjectIdGenerator<?> paramObjectIdGenerator) { if (paramObjectIdGenerator.getClass() == getClass()) { PropertyBasedObjectIdGenerator localPropertyBasedObjectIdGenerator = (PropertyBasedObjectIdGenerator)paramObjectIdGenerator; if (localPropertyBasedObjectIdGenerator.getScope() == this._scope) return localPropertyBasedObjectIdGenerator._property == this._property; } return false; }
protected ObjectIdInfo(String paramString, Class<?> paramClass, Class<? extends ObjectIdGenerator<?>> paramClass1, boolean paramBoolean) { this._propertyName = paramString; this._scope = paramClass; this._generator = paramClass1; this._alwaysAsId = paramBoolean; }
protected ObjectIdReader(JavaType paramJavaType, String paramString, ObjectIdGenerator<?> paramObjectIdGenerator, JsonDeserializer<?> paramJsonDeserializer, SettableBeanProperty paramSettableBeanProperty) { this.idType = paramJavaType; this.propertyName = paramString; this.generator = paramObjectIdGenerator; this.deserializer = paramJsonDeserializer; this.idProperty = paramSettableBeanProperty; }
protected void addObjectIdReader(DeserializationContext paramDeserializationContext, BeanDescription paramBeanDescription, BeanDeserializerBuilder paramBeanDeserializerBuilder) { ObjectIdInfo localObjectIdInfo = paramBeanDescription.getObjectIdInfo(); if (localObjectIdInfo == null) return; Class localClass = localObjectIdInfo.getGeneratorType(); SettableBeanProperty localSettableBeanProperty1; JavaType localJavaType2; Object localObject; if (localClass == ObjectIdGenerators.PropertyGenerator.class) { String str = localObjectIdInfo.getPropertyName(); SettableBeanProperty localSettableBeanProperty2 = paramBeanDeserializerBuilder.findProperty(str); localSettableBeanProperty1 = localSettableBeanProperty2; if (localSettableBeanProperty2 == null) throw new IllegalArgumentException("Invalid Object Id definition for " + paramBeanDescription.getBeanClass().getName() + ": can not find property with name '" + str + "'"); localJavaType2 = localSettableBeanProperty1.getType(); localObject = new PropertyBasedObjectIdGenerator(localObjectIdInfo.getScope()); } else { JavaType localJavaType1 = paramDeserializationContext.constructType(localClass); localJavaType2 = paramDeserializationContext.getTypeFactory().findTypeParameters(localJavaType1, ObjectIdGenerator.class)[0]; localSettableBeanProperty1 = null; localObject = paramDeserializationContext.objectIdGeneratorInstance(paramBeanDescription.getClassInfo(), localObjectIdInfo); } JsonDeserializer localJsonDeserializer = paramDeserializationContext.findRootValueDeserializer(localJavaType2); paramBeanDeserializerBuilder.setObjectIdReader(ObjectIdReader.construct(localJavaType2, localObjectIdInfo.getPropertyName(), (ObjectIdGenerator)localObject, localJsonDeserializer, localSettableBeanProperty1)); }
/** * Used by generated {@link AbstractBeanJsonSerializer} * * @param generator instance of generator to add */ @SuppressWarnings( "UnusedDeclaration" ) public void addGenerator( ObjectIdGenerator<?> generator ) { if ( null == generators ) { generators = new ArrayList<ObjectIdGenerator<?>>(); } generators.add( generator ); }
/** * Used by generated {@link AbstractBeanJsonSerializer} * * @param gen generator used to find equivalent generator * @param <T> a T object. * * @return a {@link com.fasterxml.jackson.annotation.ObjectIdGenerator} object. */ @SuppressWarnings( {"UnusedDeclaration", "unchecked"} ) public <T> ObjectIdGenerator<T> findObjectIdGenerator( ObjectIdGenerator<T> gen ) { if ( null != generators ) { for ( ObjectIdGenerator<?> generator : generators ) { if ( generator.canUseFor( gen ) ) { return (ObjectIdGenerator<T>) generator; } } } return null; }
BeanIdentityInfo( String propertyName, boolean alwaysAsId, Class<? extends ObjectIdGenerator<?>> generator, Class<?> scope ) { this.propertyName = propertyName; this.alwaysAsId = alwaysAsId; this.generator = generator; this.scope = scope; this.idABeanProperty = true; this.type = Optional.absent(); }
BeanIdentityInfo( String propertyName, boolean alwaysAsId, Class<? extends ObjectIdGenerator<?>> generator, Class<?> scope, JType type ) { this.propertyName = propertyName; this.alwaysAsId = alwaysAsId; this.generator = generator; this.scope = scope; this.idABeanProperty = false; this.type = Optional.of( type ); }
@SuppressWarnings("unchecked") protected ObjectIdWriter(JavaType t, SerializedString propName, ObjectIdGenerator<?> gen, JsonSerializer<?> ser, boolean alwaysAsId) { idType = t; propertyName = propName; generator = gen; serializer = (JsonSerializer<Object>) ser; this.alwaysAsId = alwaysAsId; }
/** * Factory method called by {@link com.fasterxml.jackson.databind.ser.std.BeanSerializerBase} * with the initial information based on standard settings for the type * for which serializer is being built. */ public static ObjectIdWriter construct(JavaType idType, String propName, ObjectIdGenerator<?> generator, boolean alwaysAsId) { SerializedString serName = (propName == null) ? null : new SerializedString(propName); return new ObjectIdWriter(idType, serName, generator, null, alwaysAsId); }
protected ObjectIdInfo(String prop, Class<?> scope, Class<? extends ObjectIdGenerator<?>> gen, boolean alwaysAsId) { _propertyName = prop; _scope = scope; _generator = gen; _alwaysAsId = alwaysAsId; }
@SuppressWarnings("unchecked") protected ObjectIdReader(JavaType t, String propName, ObjectIdGenerator<?> gen, JsonDeserializer<?> deser, SettableBeanProperty idProp) { idType = t; propertyName = propName; generator = gen; deserializer = (JsonDeserializer<Object>) deser; idProperty = idProp; }
/** * Factory method called by {@link com.fasterxml.jackson.databind.ser.std.BeanSerializerBase} * with the initial information based on standard settings for the type * for which serializer is being built. */ public static ObjectIdReader construct(JavaType idType, String propName, ObjectIdGenerator<?> generator, JsonDeserializer<?> deser, SettableBeanProperty idProp) { return new ObjectIdReader(idType, propName, generator, deser, idProp); }
protected void addObjectIdReader(DeserializationContext ctxt, BeanDescription beanDesc, BeanDeserializerBuilder builder) throws JsonMappingException { ObjectIdInfo objectIdInfo = beanDesc.getObjectIdInfo(); if (objectIdInfo == null) { return; } Class<?> implClass = objectIdInfo.getGeneratorType(); JavaType idType; SettableBeanProperty idProp; ObjectIdGenerator<?> gen; // Just one special case: Property-based generator is trickier if (implClass == ObjectIdGenerators.PropertyGenerator.class) { // most special one, needs extra work String propName = objectIdInfo.getPropertyName(); idProp = builder.findProperty(propName); if (idProp == null) { throw new IllegalArgumentException("Invalid Object Id definition for " +beanDesc.getBeanClass().getName()+": can not find property with name '"+propName+"'"); } idType = idProp.getType(); gen = new PropertyBasedObjectIdGenerator(objectIdInfo.getScope()); } else { JavaType type = ctxt.constructType(implClass); idType = ctxt.getTypeFactory().findTypeParameters(type, ObjectIdGenerator.class)[0]; idProp = null; gen = ctxt.objectIdGeneratorInstance(beanDesc.getClassInfo(), objectIdInfo); } // also: unlike with value deserializers, let's just resolve one we need here JsonDeserializer<?> deser = ctxt.findRootValueDeserializer(idType); builder.setObjectIdReader(ObjectIdReader.construct(idType, objectIdInfo.getPropertyName(), gen, deser, idProp)); }
@Override public ReadableObjectId findObjectId(Object id, ObjectIdGenerator<?> generator, ObjectIdResolver resolver) { return this.context.findObjectId(id, generator, resolver); }
@SuppressWarnings("UnusedDeclaration") void addGenerator(ObjectIdGenerator<?> generator);
@SuppressWarnings({"UnusedDeclaration", "unchecked"}) <T> ObjectIdGenerator<T> findObjectIdGenerator(ObjectIdGenerator<T> gen);
@Override public ObjectIdGenerator<Integer> forScope(Class<?> scope) { return this; }
@Override public ObjectIdGenerator<Integer> newForSerialization(Object context) { return this; }
@Override public boolean canUseFor(ObjectIdGenerator<?> gen) { return (gen.getClass() == getClass()) && (gen.getScope() == _scope); }
@Override public void bindItem(ObjectIdGenerator.IdKey id, Object pojo) { }
@Override public Object resolveId(ObjectIdGenerator.IdKey id) { return store == null ? null : store.findByKey(id.scope, id.key); }
@Override public ObjectIdGenerator<?> objectIdGeneratorInstance(MapperConfig<?> config, Annotated annotated, Class<?> implClass) { return null; }
public ObjectIdGenerator<?> objectIdGeneratorInstance(MapperConfig<?> paramMapperConfig, Annotated paramAnnotated, Class<?> paramClass) { return null; }
public WritableObjectId findObjectId(Object paramObject, ObjectIdGenerator<?> paramObjectIdGenerator) { if (this._seenObjectIds == null) { this._seenObjectIds = new IdentityHashMap(); } else { WritableObjectId localWritableObjectId1 = (WritableObjectId)this._seenObjectIds.get(paramObject); if (localWritableObjectId1 != null) return localWritableObjectId1; } Object localObject; if (this._objectIdGenerators == null) { this._objectIdGenerators = new ArrayList(8); localObject = null; } else { int i = 0; int j = this._objectIdGenerators.size(); while (true) { localObject = null; if (i >= j) break; ObjectIdGenerator localObjectIdGenerator = (ObjectIdGenerator)this._objectIdGenerators.get(i); if (localObjectIdGenerator.canUseFor(paramObjectIdGenerator)) { localObject = localObjectIdGenerator; break; } i++; } } if (localObject == null) { localObject = paramObjectIdGenerator.newForSerialization(this); this._objectIdGenerators.add(localObject); } WritableObjectId localWritableObjectId2 = new WritableObjectId((ObjectIdGenerator)localObject); this._seenObjectIds.put(paramObject, localWritableObjectId2); return localWritableObjectId2; }
public WritableObjectId(ObjectIdGenerator<?> paramObjectIdGenerator) { this.generator = paramObjectIdGenerator; }
public ObjectIdGenerator<Object> forScope(Class<?> paramClass) { if (paramClass == this._scope) return this; return new PropertyBasedObjectIdGenerator(paramClass, this._property); }
public ObjectIdGenerator.IdKey key(Object paramObject) { return new ObjectIdGenerator.IdKey(getClass(), this._scope, paramObject); }
public ObjectIdGenerator<Object> newForSerialization(Object paramObject) { return this; }