Skip to content

Commit

Permalink
Merge branch '2.18'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 18, 2024
2 parents 7e36497 + 6c782df commit efcec4e
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ protected void _validateNamedPropertyParameter(DeserializationContext ctxt,
// Must be injectable or have name; without either won't work
if ((name == null) && (injectId == null)) {
ctxt.reportBadTypeDefinition(beanDesc,
"Argument #%d of constructor %s has no property name (and is not Injectable): can not use as property-based Creator",
"Argument #%d of Creator %s has no property name (and is not Injectable): can not use as property-based Creator",
paramIndex, candidate);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package tools.jackson.databind.deser.creators;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.testutil.DatabindTestUtil;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Tests to help cover simpler cases wrt [databind#4515]
*/
public class Creators4515Test extends DatabindTestUtil
{
static class ConstructorBeanPropsExplicit {
int x;

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
protected ConstructorBeanPropsExplicit(@JsonProperty("x") int x) {
this.x = x;
}
}

static class ConstructorBeanPropsWithName {
int x;

@JsonCreator
protected ConstructorBeanPropsWithName(@JsonProperty("x") int x) {
this.x = x;
}
}

static class FactoryBeanPropsExplicit {
double d;

private FactoryBeanPropsExplicit(double value, boolean dummy) { d = value; }

@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
protected static FactoryBeanPropsExplicit createIt(@JsonProperty("f") double value) {
return new FactoryBeanPropsExplicit(value, true);
}
}

/*
/**********************************************************************
/* Test methods, simple Properties-based (constructor) explicitly annotated
/**********************************************************************
*/

private final ObjectMapper MAPPER = newJsonMapper();

@Test
public void testPropsBasedConstructorExplicit() throws Exception
{
ConstructorBeanPropsExplicit bean = MAPPER.readValue("{ \"x\" : 42 }",
ConstructorBeanPropsExplicit.class);
assertEquals(42, bean.x);
}

@Test
public void testPropsBasedConstructorWithName() throws Exception
{
ConstructorBeanPropsWithName bean = MAPPER.readValue("{ \"x\" : 28 }",
ConstructorBeanPropsWithName.class);
assertEquals(28, bean.x);
}

/*
/**********************************************************************
/* Test methods, simple Properties-based (constructor) explicitly annotated
/**********************************************************************
*/

@Test
public void testPropsBasedFactoryExplicit() throws Exception
{
FactoryBeanPropsExplicit bean = MAPPER.readValue("{ \"f\" : 0.5 }",
FactoryBeanPropsExplicit.class);
assertEquals(0.5, bean.d);
}

/*
/**********************************************************************
/* Test methods, simple Delegating, explicitly annotated
/**********************************************************************
*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,13 @@ public static TypeFactory newTypeFactory() {
/**********************************************************************
*/

public static JsonMapper newJsonMapper() {
return new JsonMapper();
public static ObjectMapper newJsonMapper() {
return jsonMapperBuilder().build();
}

public static JsonMapper.Builder jsonMapperBuilder() {
return JsonMapper.builder();
return JsonMapper.builder()
.enable(StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION);
}

/*
Expand Down

0 comments on commit efcec4e

Please sign in to comment.