Tatu Saloranta | e4f23bb | 2011-12-23 00:31:35 -0800 | [diff] [blame] | 1 | package com.fasterxml.jackson.databind.jsontype.impl; |
| 2 | |
Tatu Saloranta | 1b253d3 | 2011-12-23 00:44:25 -0800 | [diff] [blame] | 3 | import com.fasterxml.jackson.annotation.JsonTypeInfo.As; |
Tatu Saloranta | e4f23bb | 2011-12-23 00:31:35 -0800 | [diff] [blame] | 4 | |
| 5 | import com.fasterxml.jackson.databind.BeanProperty; |
Tatu Saloranta | d92c1ed | 2011-12-23 18:23:31 -0800 | [diff] [blame] | 6 | import com.fasterxml.jackson.databind.JavaType; |
Tatu Saloranta | 49b7121 | 2012-01-30 22:13:21 -0800 | [diff] [blame] | 7 | import com.fasterxml.jackson.databind.jsontype.TypeDeserializer; |
Tatu Saloranta | e4f23bb | 2011-12-23 00:31:35 -0800 | [diff] [blame] | 8 | import com.fasterxml.jackson.databind.jsontype.TypeIdResolver; |
| 9 | |
| 10 | /** |
| 11 | * Type deserializer used with {@link As#EXTERNAL_PROPERTY} inclusion mechanism. |
| 12 | * Actual implementation may look bit strange since it depends on comprehensive |
| 13 | * pre-processing done by {@link com.fasterxml.jackson.databind.deser.BeanDeserializer} |
| 14 | * to basically transform external type id into structure that looks more like |
| 15 | * "wrapper-array" style inclusion. This intermediate form is chosen to allow |
| 16 | * supporting all possible JSON structures. |
Tatu Saloranta | e4f23bb | 2011-12-23 00:31:35 -0800 | [diff] [blame] | 17 | */ |
| 18 | public class AsExternalTypeDeserializer extends AsArrayTypeDeserializer |
| 19 | { |
Tatu Saloranta | 65d186e | 2012-10-05 23:51:38 -0700 | [diff] [blame] | 20 | private static final long serialVersionUID = 1L; |
| 21 | |
Tatu Saloranta | 596c6dd | 2016-03-20 18:24:04 -0700 | [diff] [blame] | 22 | /** |
| 23 | * @since 2.8 |
| 24 | */ |
Tatu Saloranta | 49b7121 | 2012-01-30 22:13:21 -0800 | [diff] [blame] | 25 | public AsExternalTypeDeserializer(JavaType bt, TypeIdResolver idRes, |
Tatu Saloranta | 596c6dd | 2016-03-20 18:24:04 -0700 | [diff] [blame] | 26 | String typePropertyName, boolean typeIdVisible, JavaType defaultImpl) |
Tatu Saloranta | e4f23bb | 2011-12-23 00:31:35 -0800 | [diff] [blame] | 27 | { |
Tatu Saloranta | 49b7121 | 2012-01-30 22:13:21 -0800 | [diff] [blame] | 28 | super(bt, idRes, typePropertyName, typeIdVisible, defaultImpl); |
Tatu Saloranta | e4f23bb | 2011-12-23 00:31:35 -0800 | [diff] [blame] | 29 | } |
| 30 | |
Tatu Saloranta | 596c6dd | 2016-03-20 18:24:04 -0700 | [diff] [blame] | 31 | public AsExternalTypeDeserializer(AsExternalTypeDeserializer src, |
| 32 | BeanProperty property) { |
Tatu Saloranta | 49b7121 | 2012-01-30 22:13:21 -0800 | [diff] [blame] | 33 | super(src, property); |
| 34 | } |
| 35 | |
| 36 | @Override |
Tatu Saloranta | 10af6d3 | 2013-12-31 22:27:57 -0800 | [diff] [blame] | 37 | public TypeDeserializer forProperty(BeanProperty prop) { |
Tatu Saloranta | 49b7121 | 2012-01-30 22:13:21 -0800 | [diff] [blame] | 38 | if (prop == _property) { // usually if it's null |
| 39 | return this; |
| 40 | } |
| 41 | return new AsExternalTypeDeserializer(this, prop); |
| 42 | } |
| 43 | |
Tatu Saloranta | e4f23bb | 2011-12-23 00:31:35 -0800 | [diff] [blame] | 44 | @Override |
Tatu Saloranta | 10af6d3 | 2013-12-31 22:27:57 -0800 | [diff] [blame] | 45 | public As getTypeInclusion() { return As.EXTERNAL_PROPERTY; } |
Tatu Saloranta | add3cc3 | 2014-10-06 22:25:44 -0700 | [diff] [blame] | 46 | |
| 47 | // yes, very important distinction... |
| 48 | @Override |
| 49 | protected boolean _usesExternalId() { |
| 50 | return true; |
| 51 | } |
Tatu Saloranta | e4f23bb | 2011-12-23 00:31:35 -0800 | [diff] [blame] | 52 | } |