Skip to content

Commit

Permalink
Fixed #1345
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 30, 2017
1 parent 5f1039f commit 04c33a5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 37 deletions.
3 changes: 3 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Project: jackson-databind
2.8.8 (not yet released)

(partial) #994: `DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS` only works for POJOs, Maps
#1345: `@JsonProperty(access = READ_ONLY)` together with generated constructor (Lombok) causes
exception: "Could not find creator property with name ..."
(reported by Raniz85@github)
#1533: `AsPropertyTypeDeserializer` ignores `DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT`
#1543: JsonFormat.Shape.NUMBER_INT does not work when defined on enum type in 2.8
(reported by Alex P)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,11 @@ protected void addBeanProps(DeserializationContext ctxt,
BeanDescription beanDesc, BeanDeserializerBuilder builder)
throws JsonMappingException
{
final SettableBeanProperty[] creatorProps =
builder.getValueInstantiator().getFromObjectArguments(ctxt.getConfig());
final boolean isConcrete = !beanDesc.getType().isAbstract();
final SettableBeanProperty[] creatorProps = isConcrete
? builder.getValueInstantiator().getFromObjectArguments(ctxt.getConfig())
: null;
final boolean hasCreatorProps = (creatorProps != null);

// 01-May-2016, tatu: Which base type to use here gets tricky, since
// it may often make most sense to use general type for overrides,
Expand Down Expand Up @@ -490,8 +492,8 @@ protected void addBeanProps(DeserializationContext ctxt,
}
}
}
final boolean useGettersAsSetters = (ctxt.isEnabled(MapperFeature.USE_GETTERS_AS_SETTERS)
&& ctxt.isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
final boolean useGettersAsSetters = ctxt.isEnabled(MapperFeature.USE_GETTERS_AS_SETTERS)
&& ctxt.isEnabled(MapperFeature.AUTO_DETECT_GETTERS);

// Ok: let's then filter out property definitions
List<BeanPropertyDefinition> propDefs = filterBeanProps(ctxt,
Expand Down Expand Up @@ -531,7 +533,7 @@ protected void addBeanProps(DeserializationContext ctxt,
}
// 25-Sep-2014, tatu: No point in finding constructor parameters for abstract types
// (since they are never used anyway)
if (isConcrete && propDef.hasConstructorParameter()) {
if (hasCreatorProps && propDef.hasConstructorParameter()) {
/* If property is passed via constructor parameter, we must
* handle things in special way. Not sure what is the most optimal way...
* for now, let's just call a (new) method in builder, which does nothing.
Expand All @@ -548,8 +550,13 @@ protected void addBeanProps(DeserializationContext ctxt,
}
}
if (cprop == null) {
ctxt.reportMappingException("Could not find creator property with name '%s' (in class %s)",
name, beanDesc.getBeanClass().getName());
List<String> n = new ArrayList<>();
for (SettableBeanProperty cp : creatorProps) {
n.add(cp.getName());
}
ctxt.reportBadPropertyDefinition(beanDesc, propDef,
"Could not find creator property with name '%s' (known Creator properties: %s)",
name, n);
continue;
}
if (prop != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.fasterxml.jackson.databind.deser;

import java.beans.ConstructorProperties;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.*;

Expand Down Expand Up @@ -47,7 +49,22 @@ public String getLastName() {
public void setLastName(String n) {
lastName = n;
}
}
}

// for [databind#1345], emulate way Lombok embellishes classes
static class Foo1345 {
@JsonProperty(access=JsonProperty.Access.READ_ONLY)
public String id;
public String name;

@ConstructorProperties({ "id", "name" })
public Foo1345(String id, String name) {
this.id = id;
this.name = name;
}

protected Foo1345() { }
}

/*
/**********************************************************
Expand Down Expand Up @@ -75,4 +92,12 @@ public void testReadOnly935() throws Exception
Pojo935 result = MAPPER.readValue(json, Pojo935.class);
assertNotNull(result);
}

public void testReadOnly1345() throws Exception
{
Foo1345 result = MAPPER.readValue("{\"name\":\"test\"}", Foo1345.class);
assertNotNull(result);
assertEquals("test", result.name);
assertNull(result.id);
}
}
29 changes: 0 additions & 29 deletions src/test/java/com/fasterxml/jackson/failing/ReadOnly1345Test.java

This file was deleted.

0 comments on commit 04c33a5

Please sign in to comment.