Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.fasterxml.jackson.databind.ser.impl;
 
 
 
    protected final BeanPropertyWriter _property;
    
    {
        this(oid.getScope(), prop);
    }
    protected PropertyBasedObjectIdGenerator(Class<?> scopeBeanPropertyWriter prop)
    {
        super(scope);
         = prop;
    }

    
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 = (PropertyBasedObjectIdGeneratorgen;
            if (other.getScope() == ) {
                /* 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 == );
            }
        }
        return false;
    }
    
    @Override
    public Object generateId(Object forPojo) {
        try {
            return .get(forPojo);
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new IllegalStateException("Problem accessing property '"
                    +.getName()+"': "+e.getMessage(), e);
        }
    }
    @Override
    public ObjectIdGenerator<ObjectforScope(Class<?> scope) {
        return (scope == ) ? this : new PropertyBasedObjectIdGenerator(scope);
    }
    @Override
    public ObjectIdGenerator<ObjectnewForSerialization(Object context) {
        // No state, can return this
        return this;
    }
    @Override
        // should we use general type for all; or type of property itself?
        return new IdKey(getClass(), key);
    }
New to GrepCode? Check out our FAQ X