This is an automated email from the ASF dual-hosted git repository. gk pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/turbine-fulcrum-json.git
commit adb002fd31b9c15bacb2fbd1ece89e7c7466095d Author: gk <[email protected]> AuthorDate: Wed Apr 23 17:03:11 2025 +0200 Align, and fix junit5 engines and platform settings from testcontainer and junit-bom (5.11.2 and 1.11.2 in testcontainer v2.0.1), update gson to v.2.13.0. Fix profile in (old) jackson module, keep it, but set main class as deprecated, update dep commons-lang3 to 3.17.0. --- api/pom.xml | 6 ---- gson/pom.xml | 13 ++------ jackson/pom.xml | 21 +++++++----- .../fulcrum/json/jackson/JacksonMapperService.java | 29 ++++++++++++++++ .../fulcrum/json/jackson/DefaultServiceTest.java | 3 -- .../fulcrum/json/jackson/JacksonMapperTest.java | 23 +++++++++++-- jackson2/pom.xml | 39 ++++++++-------------- pom.xml | 16 +++------ 8 files changed, 82 insertions(+), 68 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 56d6c6f..c22ef81 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -42,12 +42,6 @@ <dependency> <groupId>org.apache.fulcrum</groupId> <artifactId>fulcrum-yaafi</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.13.2</version> - <scope>test</scope> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> diff --git a/gson/pom.xml b/gson/pom.xml index 46374da..b7b3514 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -49,8 +49,7 @@ <artifactId>maven-surefire-plugin</artifactId> <configuration> <includes> - <include>**/*Test.*</include> - <include>**/*TestCase.*</include> + <include>*Test*</include> </includes> </configuration> </plugin> @@ -61,7 +60,7 @@ <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> - <version>3.13.0</version> + <version>3.17.0</version> </dependency> <dependency> <groupId>org.apache.avalon.framework</groupId> @@ -79,12 +78,6 @@ <version>2.0.1</version> <scope>test</scope> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.13.2</version> - <scope>test</scope> - </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> @@ -111,6 +104,6 @@ </dependency> </dependencies> <properties> - <gson.version>2.11.0</gson.version> + <gson.version>2.13.0</gson.version> </properties> </project> diff --git a/jackson/pom.xml b/jackson/pom.xml index 4d55184..4fa0b96 100644 --- a/jackson/pom.xml +++ b/jackson/pom.xml @@ -46,12 +46,11 @@ <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> - <configuration> + <!--configuration> <includes> - <include>**/*Test.*</include> - <include>**/*TestCase.*</include> + <include>*Test.*</include> </includes> - </configuration> + </configuration--> </plugin> </plugins> </build> @@ -60,7 +59,7 @@ <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> - <version>3.13.0</version> + <version>3.17.0</version> </dependency> <dependency> <groupId>org.apache.avalon.framework</groupId> @@ -94,6 +93,12 @@ <version>1.7.36</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.apache.fulcrum</groupId> + <artifactId>fulcrum-testcontainer</artifactId> + <version>2.0.0</version> + <scope>test</scope> + </dependency> </dependencies> <properties> <!-- 1.9.13, released 14-Jul-2013: latest version see https://github.com/FasterXML/jackson --> @@ -102,14 +107,14 @@ <profiles> <profile> - <id>jkd-12-compile</id> + <id>jkd-above-12-compile</id> <activation> - <jdk>12</jdk> + <jdk>[12,]</jdk> </activation> <build> <pluginManagement> <plugins> - <plugin> + <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> diff --git a/jackson/src/java/org/apache/fulcrum/json/jackson/JacksonMapperService.java b/jackson/src/java/org/apache/fulcrum/json/jackson/JacksonMapperService.java index e2609b5..7885003 100644 --- a/jackson/src/java/org/apache/fulcrum/json/jackson/JacksonMapperService.java +++ b/jackson/src/java/org/apache/fulcrum/json/jackson/JacksonMapperService.java @@ -45,6 +45,7 @@ import org.codehaus.jackson.map.ObjectReader; import org.codehaus.jackson.map.SerializationConfig.Feature; import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector; import org.codehaus.jackson.map.module.SimpleModule; +import org.codehaus.jackson.map.ser.BeanPropertyFilter; import org.codehaus.jackson.map.ser.FilterProvider; import org.codehaus.jackson.map.ser.StdSerializerProvider; import org.codehaus.jackson.map.ser.impl.SimpleBeanPropertyFilter; @@ -60,11 +61,13 @@ import org.codehaus.jackson.map.ser.impl.SimpleFilterProvider; * Note: Filters could not easily unregistered. Try setting @link * {@link #cacheFilters} to <code>false</code>. * + * Use Jackson2MapperService in module jackson2 * * @author gk * @version $Id$ * */ +@Deprecated public class JacksonMapperService extends AbstractLogEnabled implements JsonService, Initializable, Configurable { @@ -512,4 +515,30 @@ public class JacksonMapperService extends AbstractLogEnabled implements } } + @Override + public <T> T convertWithFilter(Object src, Class<T> type, String... filterAttrs) throws Exception + { + if (filterAttrs != null && filterAttrs.length > 0 && !"".equals(filterAttrs[0])) { + BeanPropertyFilter pf = SimpleBeanPropertyFilter.filterOutAllExcept(filterAttrs); + SimpleFilterProvider filter = null; + if (pf != null) { + filter = new SimpleFilterProvider(); + filter.setDefaultFilter(pf); + getMapper().setFilters( filter ); + } + String json = ser( src, filter ); + T filteredObject = (T) deSer( json, type ); + getLogger().debug( "filtered Object: " + filteredObject ); + return filteredObject; + } else { + return null; + } + } + + @Override + public <T> T convertWithFilter(Object src, String... filterAttrs) throws Exception + { + return convertWithFilter(src, (Class<T>) src.getClass(), filterAttrs); + } + } diff --git a/jackson/src/test/org/apache/fulcrum/json/jackson/DefaultServiceTest.java b/jackson/src/test/org/apache/fulcrum/json/jackson/DefaultServiceTest.java index a45f624..dfc7035 100644 --- a/jackson/src/test/org/apache/fulcrum/json/jackson/DefaultServiceTest.java +++ b/jackson/src/test/org/apache/fulcrum/json/jackson/DefaultServiceTest.java @@ -7,8 +7,6 @@ import org.apache.fulcrum.json.TestClass; import org.apache.fulcrum.testcontainer.BaseUnit5Test; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; /** @@ -17,7 +15,6 @@ import org.junit.runner.RunWith; * @author gk * @version $Id$ */ -@RunWith(JUnitPlatform.class) public class DefaultServiceTest extends BaseUnit5Test { private JsonService sc = null; private final String preDefinedOutput = diff --git a/jackson/src/test/org/apache/fulcrum/json/jackson/JacksonMapperTest.java b/jackson/src/test/org/apache/fulcrum/json/jackson/JacksonMapperTest.java index 62d8f4a..7b12faf 100644 --- a/jackson/src/test/org/apache/fulcrum/json/jackson/JacksonMapperTest.java +++ b/jackson/src/test/org/apache/fulcrum/json/jackson/JacksonMapperTest.java @@ -39,9 +39,8 @@ import org.apache.fulcrum.testcontainer.BaseUnit5Test; import org.codehaus.jackson.annotate.JsonIgnore; import org.codehaus.jackson.annotate.JsonProperty; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.platform.runner.JUnitPlatform; -import org.junit.runner.RunWith; /** * Jackson1 JSON Test @@ -49,7 +48,6 @@ import org.junit.runner.RunWith; * @author gk * @version $Id$ */ -@RunWith(JUnitPlatform.class) public class JacksonMapperTest extends BaseUnit5Test { private JsonService sc = null; private final String preDefinedOutput = "{\"container\":{\"cf\":\"Config.xml\"},\"configurationName\":\"Config.xml\",\"name\":\"mytest\"}"; @@ -114,6 +112,25 @@ public class JacksonMapperTest extends BaseUnit5Test { Object deson = sc.deSer(serJson, TestClass.class); assertEquals(TestClass.class, deson.getClass(), "DeSer failed "); } + + // this fails with unrecognized field "size" (Class org.apache.fulcrum.json.Rectangle), not marked as ignorable + // in at org.apache.fulcrum.json.jackson.JacksonMapperService.deSer(JacksonMapperService.java:152) + @Disabled + // @Test + public void testConvertWithFilteredpropsMixin() throws Exception { + Rectangle rectangle = new Rectangle(5, 10); + rectangle.setName("jim"); + + String[] filterAttrs = new String[]{"name"}; + Rectangle filteredRectangle = ((JacksonMapperService)sc).convertWithFilter(rectangle, Rectangle.class, filterAttrs); + System.out.println( "1 filteredRectangle: "+ filteredRectangle ); + assertTrue( filteredRectangle.getName() != null ); + assertTrue( filteredRectangle.getName().equals( "jim" ) ); + // example with default from src.getClass() + filteredRectangle = ((JacksonMapperService)sc).convertWithFilter(rectangle, "h","w","size"); + System.out.println( "2 filteredRectangle: "+ filteredRectangle ); + assertTrue( filteredRectangle.getName() == null ); + } // public void testDeserializationCollection() throws Exception { // List<Rectangle> rectList = new ArrayList<Rectangle>(); diff --git a/jackson2/pom.xml b/jackson2/pom.xml index fb6848e..ae7c88b 100644 --- a/jackson2/pom.xml +++ b/jackson2/pom.xml @@ -48,8 +48,7 @@ <artifactId>maven-surefire-plugin</artifactId> <configuration> <includes> - <include>**/*Test.*</include> - <include>**/*TestCase.*</include> + <include>*Test*</include> </includes> </configuration> </plugin> @@ -60,7 +59,7 @@ <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> - <version>3.12.0</version> + <version>3.17.0</version> </dependency> <dependency> <groupId>org.apache.avalon.framework</groupId> @@ -77,12 +76,11 @@ <artifactId>fulcrum-yaafi</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.13.2</version> - <scope>test</scope> - </dependency> + <dependency> + <groupId>org.apache.fulcrum</groupId> + <artifactId>fulcrum-testcontainer</artifactId> + <scope>test</scope> + </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> @@ -138,26 +136,15 @@ <optional>true</optional> <scope>test</scope> </dependency> + <dependency> + <groupId>org.junit.platform</groupId> + <artifactId>junit-platform-launcher</artifactId> + </dependency> </dependencies> <properties> <!-- 2.7.x hase Java 7 baseline, but is compiled with Java 6 support, cft. https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.7. 2.14 has java 8 baseline, with Jackson 2.8, Java 7 languages features will be allowed --> - <jackson2.version>2.16.1</jackson2.version> + <jackson2.version>2.18.3</jackson2.version> </properties> - <profiles> - <profile> - <id>java12</id> - <activation> - <jdk>[12,)</jdk> - </activation> - <dependencies> - <!-- removal of jaxb in java 12: https://docs.oracle.com/en/java/javase/12/migrate/index.html --> - <dependency> - <groupId>org.glassfish.jaxb</groupId> - <artifactId>jaxb-runtime</artifactId> - <version>4.0.3</version> - </dependency> - </dependencies> - </profile> - </profiles> + </project> diff --git a/pom.xml b/pom.xml index 4da43ec..8b69674 100644 --- a/pom.xml +++ b/pom.xml @@ -164,12 +164,13 @@ <version>${turbine.log4j2.version}</version> <scope>test</scope> </dependency> + <!-- check compatilble versions in junit-bom --> <dependency> <groupId>org.junit.platform</groupId> - <artifactId>junit-platform-runner</artifactId> - <version>1.11.0-M2</version> + <artifactId>junit-platform-launcher</artifactId> + <version>1.11.2</version><!-- 1.11.2 ~ 5.11.2, 1.12.2 compatible with 5.12.2, see junit-bom --> <scope>test</scope> - </dependency> + </dependency> </dependencies> </dependencyManagement> @@ -182,15 +183,6 @@ <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> </dependency> - <dependency> - <groupId>org.junit.platform</groupId> - <artifactId>junit-platform-runner</artifactId> - </dependency> - <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter</artifactId> - <version>5.11.0-M2</version> - </dependency> </dependencies> <properties>
