Skip to content

Commit

Permalink
Merge branch '2.14' into 2.15
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 18, 2023
2 parents 3291911 + 04d7ae4 commit 3168975
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.fasterxml.jackson.databind.records;

import com.fasterxml.jackson.annotation.JsonProperty;

import com.fasterxml.jackson.databind.*;

public class RecordFailingSetter3938Test extends BaseMapTest
{
private final static String ERROR_3938_PREFIX = "Non-null 'options' not allowed for ";

// [databind#3938]
interface NoOptionsCommand {
@JsonProperty("options")
default void setOptions(JsonNode value) {
if (value.isNull()) {
return;
}
throw new IllegalArgumentException(ERROR_3938_PREFIX+getClass().getName());
}
}

public record Command3938(int id, String filter) implements NoOptionsCommand {
}

private final ObjectMapper MAPPER = newJsonMapper();

// [databind#3938]: Should detect and use setters too
public void testFailingSetter3939() throws Exception
{
final ObjectReader R = MAPPER.readerFor(Command3938.class);

// First, missing value and `null` are fine
assertNotNull(R.readValue(a2q("{'id':1, 'filter':'abc'}")));
assertNotNull(R.readValue(a2q("{'id':2, 'filter':'def', 'options':null}")));

// But then failure for non-empty Array (f.ex)
try {
R.readValue(a2q("{'id':3, 'filter':'xyz', 'options':[ 123 ]}"));
fail("Should not pass");
} catch (DatabindException e) {
verifyException(e, ERROR_3938_PREFIX);
}
}
}

0 comments on commit 3168975

Please sign in to comment.