Skip to content

Commit

Permalink
Start work on Boolean, for #2113
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 20, 2019
1 parent ab9413a commit 9874b0e
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.*;
Expand Down Expand Up @@ -444,6 +445,37 @@ public B clearProblemHandlers() {
return _this();
}

/*
/**********************************************************************
/* Changing global defaults
/**********************************************************************
*/

public B defaultSetterInfo(JsonSetter.Value v) {
_mapper.setDefaultSetterInfo(v);
return _this();
}

/**
* Method for setting default Setter configuration, regarding things like
* merging, null-handling; used for properties for which there are
* no per-type or per-property overrides (via annotations or config overrides).
*/
public B defaultMergeable(Boolean b) {
_mapper.setDefaultMergeable(b);
return _this();
}

/**
* Method for setting default Setter configuration, regarding things like
* merging, null-handling; used for properties for which there are
* no per-type or per-property overrides (via annotations or config overrides).
*/
public B defaultLeniency(Boolean b) {
_mapper.setDefaultLeniency(b);
return _this();
}

/*
/**********************************************************************
/* Changing settings, date/time
Expand Down
18 changes: 11 additions & 7 deletions src/test/java/com/fasterxml/jackson/databind/BaseMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,27 @@ public String deserialize(JsonParser p, DeserializationContext ctxt)

private static ObjectMapper SHARED_MAPPER;

protected ObjectMapper objectMapper() {
protected ObjectMapper sharedMapper() {
if (SHARED_MAPPER == null) {
SHARED_MAPPER = newObjectMapper();
}
return SHARED_MAPPER;
}

protected ObjectMapper objectMapper() {
return sharedMapper();
}

protected ObjectWriter objectWriter() {
return objectMapper().writer();
return sharedMapper().writer();
}

protected ObjectReader objectReader() {
return objectMapper().reader();
return sharedMapper().reader();
}

protected ObjectReader objectReader(Class<?> cls) {
return objectMapper().readerFor(cls);
return sharedMapper().readerFor(cls);
}

// @since 2.9
Expand Down Expand Up @@ -302,13 +306,13 @@ protected String serializeAsString(ObjectMapper m, Object value)
protected String serializeAsString(Object value)
throws IOException
{
return serializeAsString(objectMapper(), value);
return serializeAsString(sharedMapper(), value);
}

protected String asJSONObjectValueString(Object... args)
throws IOException
{
return asJSONObjectValueString(objectMapper(), args);
return asJSONObjectValueString(sharedMapper(), args);
}

protected String asJSONObjectValueString(ObjectMapper m, Object... args)
Expand All @@ -330,7 +334,7 @@ protected String asJSONObjectValueString(ObjectMapper m, Object... args)
protected <T> T readAndMapFromString(String input, Class<T> cls)
throws IOException
{
return readAndMapFromString(objectMapper(), input, cls);
return readAndMapFromString(sharedMapper(), input, cls);
}

protected <T> T readAndMapFromString(ObjectMapper m, String input, Class<T> cls) throws IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class DatabindContextTest extends BaseMapTest
{
private final ObjectMapper MAPPER = objectMapper();
private final ObjectMapper MAPPER = sharedMapper();

public void testDeserializationContext() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.fasterxml.jackson.databind.deser.jdk;

import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;

public class JDKNumberLeniencyTest extends BaseMapTest
{
final ObjectMapper VANILLA_MAPPER = sharedMapper();

final ObjectMapper STRICT_MAPPER = jsonMapperBuilder()
.defaultLeniency(false)
.build();

public void testBooleanLeniencyInts() throws Exception
{
// First: read from integers fine by default
assertEquals(Boolean.TRUE, VANILLA_MAPPER.readValue("1", Boolean.class));
assertEquals(Boolean.TRUE,
VANILLA_MAPPER.readValue("{\"b\" : 3}", BooleanWrapper.class).b);

// But not with strict handling, first by global settings
/*
_verifyCoercionFailure(STRICT_MAPPER, "0", Boolean.class);
_verifyCoercionFailure(STRICT_MAPPER, "{\"b\" : 1}", BooleanWrapper.class);
*/
}

protected void _verifyCoercionFailure(ObjectMapper mapper, String json, Class<?> type)
throws Exception
{
try {
VANILLA_MAPPER.readValue("1", Boolean.class);
fail("Should not allow read in strict mode");
} catch (MismatchedInputException e) {
verifyException(e, "foo");
}
}

// protected ObjectMapper _
}

0 comments on commit 9874b0e

Please sign in to comment.