String id = t.hasName() ? t.getName() : _defaultTypeId(cls); if (forSer) { typeToId.put(cls.getName(), id); return new TypeNameIdResolver(config, baseType, typeToId, idToType);
/** * Helper method that will either return configured custom * type id resolver, or construct a standard resolver * given configuration. */ protected TypeIdResolver idResolver(MapperConfig<?> config, JavaType baseType, Collection<NamedType> subtypes, boolean forSer, boolean forDeser) { // Custom id resolver? if (_customIdResolver != null) { return _customIdResolver; } if (_idType == null) throw new IllegalStateException("Cannot build, 'init()' not yet called"); switch (_idType) { case CLASS: return new ClassNameIdResolver(baseType, config.getTypeFactory()); case MINIMAL_CLASS: return new MinimalClassNameIdResolver(baseType, config.getTypeFactory()); case NAME: return TypeNameIdResolver.construct(config, baseType, subtypes, forSer, forDeser); case NONE: // hmmh. should never get this far with 'none' return null; case CUSTOM: // need custom resolver... } throw new IllegalStateException("Do not know how to construct standard type id resolver for idType: "+_idType); } }
@Override public String idFromValueAndType(Object value, Class<?> type) { /* 18-Jan-2013, tatu: We may be called with null value occasionally * it seems; nothing much we can figure out that way. */ if (value == null) { return idFromClass(type); } return idFromValue(value); }
protected String idFromClass(Class<?> clazz) { if (clazz == null) { return null; } Class<?> cls = _typeFactory.constructType(clazz).getRawClass(); final String key = cls.getName(); String name; synchronized (_typeToId) { name = _typeToId.get(key); if (name == null) { // 24-Feb-2011, tatu: As per [JACKSON-498], may need to dynamically look up name // can either throw an exception, or use default name... if (_config.isAnnotationProcessingEnabled()) { BeanDescription beanDesc = _config.introspectClassAnnotations(cls); name = _config.getAnnotationIntrospector().findTypeName(beanDesc.getClassInfo()); } if (name == null) { // And if still not found, let's choose default? name = _defaultTypeId(cls); } _typeToId.put(key, name); } } return name; }
@Override public String idFromValueAndType(Object value, Class<?> type) { /* 18-Jan-2013, tatu: We may be called with null value occasionally * it seems; nothing much we can figure out that way. */ if (value == null) { return null; } return idFromValue(value); }
@Override public JavaType typeFromId(DatabindContext context, String id) { return _typeFromId(id); }
@Override public String idFromValue(Object value) { return idFromClass(value.getClass()); }
public String idFromValue(Object value) { Class<?> cls = value.getClass(); final String key = cls.getName(); String name; synchronized (_typeToId) { name = _typeToId.get(key); if (name == null) { // 24-Feb-2011, tatu: As per [JACKSON-498], may need to dynamically look up name // can either throw an exception, or use default name... if (_config.isAnnotationProcessingEnabled()) { BeanDescription beanDesc = _config.introspectClassAnnotations(cls); name = _config.getAnnotationIntrospector().findTypeName(beanDesc.getClassInfo()); } if (name == null) { // And if still not found, let's choose default? name = _defaultTypeId(cls); } _typeToId.put(key, name); } } return name; }
@Override public String idFromValueAndType(Object value, Class<?> type) { /* 18-Jan-2013, tatu: We may be called with null value occasionally * it seems; nothing much we can figure out that way. */ if (value == null) { return null; } return idFromValue(value); }
@Override public JavaType typeFromId(DatabindContext context, String id) { return _typeFromId(id); }
@Override public String idFromValue(Object value) { return idFromClass(value.getClass()); }
String id = t.hasName() ? t.getName() : _defaultTypeId(cls); if (forSer) { typeToId.put(cls.getName(), id); return new TypeNameIdResolver(config, baseType, typeToId, idToType);
public String idFromValue(Object value) { Class<?> cls = value.getClass(); final String key = cls.getName(); String name; synchronized (_typeToId) { name = _typeToId.get(key); if (name == null) { // 24-Feb-2011, tatu: As per [JACKSON-498], may need to dynamically look up name // can either throw an exception, or use default name... if (_config.isAnnotationProcessingEnabled()) { BeanDescription beanDesc = _config.introspectClassAnnotations(cls); name = _config.getAnnotationIntrospector().findTypeName(beanDesc.getClassInfo()); } if (name == null) { // And if still not found, let's choose default? name = _defaultTypeId(cls); } _typeToId.put(key, name); } } return name; }
/** * Helper method that will either return configured custom * type id resolver, or construct a standard resolver * given configuration. */ protected TypeIdResolver idResolver(MapperConfig<?> config, JavaType baseType, Collection<NamedType> subtypes, boolean forSer, boolean forDeser) { // Custom id resolver? if (_customIdResolver != null) { return _customIdResolver; } if (_idType == null) throw new IllegalStateException("Cannot build, 'init()' not yet called"); switch (_idType) { case CLASS: return new ClassNameIdResolver(baseType, config.getTypeFactory()); case MINIMAL_CLASS: return new MinimalClassNameIdResolver(baseType, config.getTypeFactory()); case NAME: return TypeNameIdResolver.construct(config, baseType, subtypes, forSer, forDeser); case NONE: // hmmh. should never get this far with 'none' return null; case CUSTOM: // need custom resolver... } throw new IllegalStateException("Do not know how to construct standard type id resolver for idType: "+_idType); } }
@Override public String idFromValueAndType(Object value, Class<?> type) { /* 18-Jan-2013, tatu: We may be called with null value occasionally * it seems; nothing much we can figure out that way. */ if (value == null) { return idFromClass(type); } return idFromValue(value); }
public String idFromValueAndType(Object value, Class<?> type) { return idFromValue(value); }
@Override public JavaType typeFromId(DatabindContext context, String id) { return _typeFromId(id); }
@Override public String idFromValue(Object value) { return idFromClass(value.getClass()); }
String id = t.hasName() ? t.getName() : _defaultTypeId(cls); if (forSer) { typeToId.put(cls.getName(), id); return new TypeNameIdResolver(config, baseType, typeToId, idToType);
@Override public String idFromValue(Object value) { Class<?> cls = _typeFactory.constructType(value.getClass()).getRawClass(); final String key = cls.getName(); String name; synchronized (_typeToId) { name = _typeToId.get(key); if (name == null) { // 24-Feb-2011, tatu: As per [JACKSON-498], may need to dynamically look up name // can either throw an exception, or use default name... if (_config.isAnnotationProcessingEnabled()) { BeanDescription beanDesc = _config.introspectClassAnnotations(cls); name = _config.getAnnotationIntrospector().findTypeName(beanDesc.getClassInfo()); } if (name == null) { // And if still not found, let's choose default? name = _defaultTypeId(cls); } _typeToId.put(key, name); } } return name; }