-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable Jackson's FAIL_ON_UNKNOWN_PROPERTIES by default
Also provide a way to go back to the previous behavior.
- Loading branch information
Showing
10 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...yment/src/test/java/io/quarkus/jackson/deployment/JacksonFailOnUnknownPropertiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.quarkus.jackson.deployment; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class JacksonFailOnUnknownPropertiesTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withConfigurationResource("application-fail-on-unknown-properties.properties"); | ||
|
||
@Inject | ||
ObjectMapper objectMapper; | ||
|
||
@Test | ||
public void testFailOnUnknownProperties() throws JsonMappingException, JsonProcessingException { | ||
Assertions.assertThrows(UnrecognizedPropertyException.class, | ||
() -> objectMapper.readValue("{\"property\": \"name\", \"unknownProperty\": \"unknown\"}", Pojo.class)); | ||
} | ||
|
||
public static class Pojo { | ||
|
||
public String property; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...yment/src/test/java/io/quarkus/jackson/deployment/JacksonIgnoreUnknownPropertiesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.quarkus.jackson.deployment; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class JacksonIgnoreUnknownPropertiesTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest(); | ||
|
||
@Inject | ||
ObjectMapper objectMapper; | ||
|
||
@Test | ||
public void testIgnoreUnknownProperties() throws JsonMappingException, JsonProcessingException { | ||
Pojo pojo = objectMapper.readValue("{\"property\": \"name\", \"unknownProperty\": \"unknown\"}", Pojo.class); | ||
assertEquals("name", pojo.property); | ||
} | ||
|
||
public static class Pojo { | ||
|
||
public String property; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...s/jackson/deployment/src/test/resources/application-fail-on-unknown-properties.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
quarkus.jackson.fail-on-unknown-properties=true |
16 changes: 16 additions & 0 deletions
16
...ions/jackson/runtime/src/main/java/io/quarkus/jackson/runtime/JacksonBuildTimeConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.quarkus.jackson.runtime; | ||
|
||
import io.quarkus.runtime.annotations.ConfigItem; | ||
import io.quarkus.runtime.annotations.ConfigRoot; | ||
|
||
@ConfigRoot | ||
public class JacksonBuildTimeConfig { | ||
|
||
/** | ||
* If enabled, Jackson will fail when encountering unknown properties. | ||
* <p> | ||
* You can still override it locally with {@code @JsonIgnoreProperties(ignoreUnknown = false)}. | ||
*/ | ||
@ConfigItem(defaultValue = "false") | ||
public boolean failOnUnknownProperties; | ||
} |
14 changes: 14 additions & 0 deletions
14
...nsions/jackson/runtime/src/main/java/io/quarkus/jackson/runtime/JacksonConfigSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.quarkus.jackson.runtime; | ||
|
||
public class JacksonConfigSupport { | ||
|
||
private boolean failOnUnknownProperties; | ||
|
||
public JacksonConfigSupport(boolean failOnUnknownProperties) { | ||
this.failOnUnknownProperties = failOnUnknownProperties; | ||
} | ||
|
||
public boolean isFailOnUnknownProperties() { | ||
return failOnUnknownProperties; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
extensions/jackson/runtime/src/main/java/io/quarkus/jackson/runtime/JacksonRecorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.quarkus.jackson.runtime; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import io.quarkus.runtime.annotations.Recorder; | ||
|
||
@Recorder | ||
public class JacksonRecorder { | ||
|
||
public Supplier<JacksonConfigSupport> jacksonConfigSupport(JacksonBuildTimeConfig jacksonBuildTimeConfig) { | ||
return new Supplier<JacksonConfigSupport>() { | ||
|
||
@Override | ||
public JacksonConfigSupport get() { | ||
return new JacksonConfigSupport(jacksonBuildTimeConfig.failOnUnknownProperties); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters