private void getIdentityInfo(ClassInformation information, ReflectClass<?> cls) { JsonIdentityInfo identity = cls.getAnnotation(JsonIdentityInfo.class); if (identity == null) { return; } Class<?> generator = identity.generator(); if (generator.equals(ObjectIdGenerators.IntSequenceGenerator.class)) { information.idGenerator = IdGeneratorType.INTEGER; } else if (generator.equals(ObjectIdGenerators.PropertyGenerator.class)) { information.idGenerator = IdGeneratorType.PROPERTY; } else if (generator.equals(ObjectIdGenerators.None.class)) { information.idGenerator = IdGeneratorType.NONE; } else { information.idGenerator = IdGeneratorType.NONE; diagnostics.warning(null, "{{t0}}: unsupported identity generator {{t1}}", cls, generator); } if (information.idGenerator == IdGeneratorType.NONE) { information.idProperty = null; } else { information.idProperty = identity.property(); } }
@JsonProperty @JacksonXmlElementWrapper( localName = "organisationUnits", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlProperty( localName = "organisationUnit", namespace = DxfNamespaces.DXF_2_0 ) @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id") @JsonIdentityReference(alwaysAsId=true) public Set<OrganisationUnit> getOrganisationUnits() { return organisationUnits; }
@Override public ObjectIdInfo findObjectIdInfo(Annotated annotated) { Class<?> rawClass = annotated.getType().getRawClass(); for (Type<?> type : model.getTypes()) { if (type.getClassType() == rawClass && type.getSingleKeyAttribute() != null) { Attribute<?, ?> attribute = type.getSingleKeyAttribute(); String name = removePrefix(attribute.getPropertyName()); if (useTableNames) { name = attribute.getName(); } // if the name is overridden use that Class<?> superClass = rawClass.getSuperclass(); while (superClass != Object.class && superClass != null) { try { Field field = superClass.getDeclaredField(attribute.getPropertyName()); JsonProperty jsonProperty = field.getAnnotation(JsonProperty.class); if (jsonProperty != null) { name = jsonProperty.value(); break; } } catch (NoSuchFieldException ignored) { } superClass = superClass.getSuperclass(); } return new ObjectIdInfo(new PropertyName(name), rawClass, ObjectIdGenerators.PropertyGenerator.class, EntityStoreResolver.class); } } return super.findObjectIdInfo(annotated); }
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)); }
@JsonIdentityReference(alwaysAsId = true) @JsonIdentityInfo( resolver = ByidInstanceResolver.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") Byid b();
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") @JsonIdentityReference(alwaysAsId = true) public TurMLCategory getTurMLCategory() { return this.turMLCategory; }
public IdParameterWrapper( @JsonProperty( "node" ) @JsonIdentityInfo( generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id" ) ValueParameterNode node ) { this.test = node; }
public IdParameterWrapperExt( @JsonProperty( "node" ) @JsonIdentityInfo( generator = ObjectIdGenerators.PropertyGenerator.class, property = "customId" ) ValueParameterNodeExt node ) { this.test = node; }
/** * Although most of post-processing is done in resolve(), we only get * access to referring property's annotations here; and this is needed * to support per-property ObjectIds. * We will also consider Shape transformations (read from Array) at this * point, since it may come from either Class definition or property. */ // @Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { ObjectIdReader oir = _objectIdReader; String[] ignorals = null; // First: may have an override for Object Id: final AnnotationIntrospector intr = ctxt.getAnnotationIntrospector(); final AnnotatedMember accessor = (property == null || intr == null) ? null : property.getMember(); if (property != null && intr != null) { ignorals = intr.findPropertiesToIgnore(accessor); ObjectIdInfo objectIdInfo = intr.findObjectIdInfo(accessor); if (objectIdInfo != null) { // some code duplication here as well (from BeanDeserializerFactory) // 2.1: allow modifications by "id ref" annotations as well: objectIdInfo = intr.findObjectReferenceInfo(accessor, objectIdInfo); Class<?> implClass = objectIdInfo.getGeneratorType(); // Property-based generator is trickier JavaType idType; SettableBeanProperty idProp; ObjectIdGenerator<?> idGen; if (implClass == ObjectIdGenerators.PropertyGenerator.class) { String propName = objectIdInfo.getPropertyName(); idProp = findProperty(propName); if (idProp == null) { throw new IllegalArgumentException("Invalid Object Id definition for " +getBeanClass().getName()+": can not find property with name '"+propName+"'"); } idType = idProp.getType(); idGen = new PropertyBasedObjectIdGenerator(objectIdInfo.getScope()); } else { // other types need to be simpler JavaType type = ctxt.constructType(implClass); idType = ctxt.getTypeFactory().findTypeParameters(type, ObjectIdGenerator.class)[0]; idProp = null; idGen = ctxt.objectIdGeneratorInstance(accessor, objectIdInfo); } JsonDeserializer<?> deser = ctxt.findRootValueDeserializer(idType); oir = ObjectIdReader.construct(idType, objectIdInfo.getPropertyName(), idGen, deser, idProp); } } // either way, need to resolve serializer: BeanDeserializerBase contextual = this; if (oir != null && oir != _objectIdReader) { contextual = contextual.withObjectIdReader(oir); } // And possibly add more properties to ignore if (ignorals != null && ignorals.length != 0) { HashSet<String> newIgnored = ArrayBuilders.setAndArray(contextual._ignorableProps, ignorals); contextual = contextual.withIgnorableProperties(newIgnored); } // One more thing: are we asked to serialize POJO as array? JsonFormat.Shape shape = null; if (accessor != null) { JsonFormat.Value format = intr.findFormat((Annotated) accessor); if (format != null) { shape = format.getShape(); } } if (shape == null) { shape = _serializationShape; } if (shape == JsonFormat.Shape.ARRAY) { contextual = contextual.asArrayDeserializer(); } return contextual; }