Skip to content

Commit

Permalink
Adopt Jackson 2.18.0
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <[email protected]>
  • Loading branch information
jansupol authored and senivam committed Oct 9, 2024
1 parent 2edf756 commit ff5f5a8
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 29 deletions.
2 changes: 1 addition & 1 deletion NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Javassist Version 3.30.2-GA
* Project: http://www.javassist.org/
* Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.

Jackson JAX-RS Providers Version 2.17.2
Jackson JAX-RS Providers Version 2.18.0
* License: Apache License, 2.0
* Project: https://github.com/FasterXML/jackson-jaxrs-providers
* Copyright: (c) 2009-2024 FasterXML, LLC. All rights reserved unless otherwise indicated.
Expand Down
2 changes: 1 addition & 1 deletion examples/NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Javassist Version 3.30.2-GA
* Project: http://www.javassist.org/
* Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.

Jackson JAX-RS Providers Version 2.17.2
Jackson JAX-RS Providers Version 2.18.0
* License: Apache License, 2.0
* Project: https://github.com/FasterXML/jackson-jaxrs-providers
* Copyright: (c) 2009-2023 FasterXML, LLC. All rights reserved unless otherwise indicated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.StreamReadConstraints;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.json.PackageVersion;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectReader;
Expand Down Expand Up @@ -128,17 +130,22 @@ private void updateFactoryConstraints(JsonFactory jsonFactory) {

if (maxStringLength != StreamReadConstraints.DEFAULT_MAX_STRING_LEN) {
final StreamReadConstraints constraints = jsonFactory.streamReadConstraints();
jsonFactory.setStreamReadConstraints(
StreamReadConstraints.builder()
// our
.maxStringLength(maxStringLength)
// customers
.maxDocumentLength(constraints.getMaxDocumentLength())
.maxNameLength(constraints.getMaxNameLength())
.maxNestingDepth(constraints.getMaxNestingDepth())
.maxNumberLength(constraints.getMaxNumberLength())
.build()
);
StreamReadConstraints.Builder builder = StreamReadConstraints.builder()
// our
.maxStringLength(maxStringLength)
// customers
.maxDocumentLength(constraints.getMaxDocumentLength())
.maxNameLength(constraints.getMaxNameLength())
.maxNestingDepth(constraints.getMaxNestingDepth())
.maxNumberLength(constraints.getMaxNumberLength());

if (PackageVersion.VERSION.getMinorVersion() >= 18) {
builder.maxTokenCount(constraints.getMaxTokenCount());
} else {
LOGGER.warning(LocalizationMessages.ERROR_JACKSON_STREAMREADCONSTRAINTS_218("maxTokenCount"));
}

jsonFactory.setStreamReadConstraints(builder.build());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.util.LookupCache;
import com.fasterxml.jackson.databind.util.LRUMap;
import com.fasterxml.jackson.databind.type.TypeFactory;

Expand Down Expand Up @@ -186,14 +187,12 @@ public abstract class ProviderBase<
/**
* Cache for resolved endpoint configurations when reading JSON data
*/
protected final LRUMap<AnnotationBundleKey, EP_CONFIG> _readers
= new LRUMap<AnnotationBundleKey, EP_CONFIG>(16, 120);
protected final LookupCache<AnnotationBundleKey, EP_CONFIG> _readers;

/**
* Cache for resolved endpoint configurations when writing JSON data
*/
protected final LRUMap<AnnotationBundleKey, EP_CONFIG> _writers
= new LRUMap<AnnotationBundleKey, EP_CONFIG>(16, 120);
protected final LookupCache<AnnotationBundleKey, EP_CONFIG> _writers;

/*
/**********************************************************
Expand All @@ -202,8 +201,9 @@ public abstract class ProviderBase<
*/

protected ProviderBase(MAPPER_CONFIG mconfig) {
_mapperConfig = mconfig;
_jaxRSFeatures = JAXRS_FEATURE_DEFAULTS;
this(mconfig,
new LRUMap<>(16, 120),
new LRUMap<>(16, 120));
}

/**
Expand All @@ -214,8 +214,19 @@ protected ProviderBase(MAPPER_CONFIG mconfig) {
*/
@Deprecated // just to denote it should NOT be directly called; will NOT be removed
protected ProviderBase() {
_mapperConfig = null;
this(null);
}
/**
* @since 2.17
*/
protected ProviderBase(MAPPER_CONFIG mconfig,
LookupCache<AnnotationBundleKey, EP_CONFIG> readerCache,
LookupCache<AnnotationBundleKey, EP_CONFIG> writerCache)
{
_mapperConfig = mconfig;
_jaxRSFeatures = JAXRS_FEATURE_DEFAULTS;
_readers = readerCache;
_writers = writerCache;
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
@Provider
@Consumes(MediaType.WILDCARD) // NOTE: required to support "non-standard" JSON variants
@Produces(MediaType.WILDCARD)
@Produces({MediaType.APPLICATION_JSON, "text/json", MediaType.WILDCARD})
public class JacksonJaxbJsonProvider extends JacksonJsonProvider {
/**
* Default annotation sets to use, if not explicitly defined during
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
*/
@Provider
@Consumes(MediaType.WILDCARD) // NOTE: required to support "non-standard" JSON variants
@Produces(MediaType.WILDCARD)
@Produces({MediaType.APPLICATION_JSON, "text/json", MediaType.WILDCARD})
public class JacksonJsonProvider
extends ProviderBase<JacksonJsonProvider,
ObjectMapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
public final class PackageVersion implements Versioned {
public final static Version VERSION = VersionUtil.parseVersion(
"2.17.2", "com.fasterxml.jackson.jaxrs", "jackson-jaxrs-json-provider");
"2.18.0", "com.fasterxml.jackson.jaxrs", "jackson-jaxrs-json-provider");

@Override
public Version version() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Miscellaneous helper classes used by providers.
*/
package com.fasterxml.jackson.jaxrs.util;
package org.glassfish.jersey.jackson.internal.jackson.jaxrs.util;
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ The project maintains the following source code repositories:

## Third-party Content

Jackson JAX-RS Providers version 2.17.2
Jackson JAX-RS Providers version 2.18.0
* License: Apache License, 2.0
* Project: https://github.com/FasterXML/jackson-jaxrs-providers
* Copyright: (c) 2009-2023 FasterXML, LLC. All rights reserved unless otherwise indicated.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
#
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
#

error.jackson.streamreadconstraints=Error setting StreamReadConstraints: {0}. Possibly not Jackson 2.15?
error.jackson.streamreadconstraints218=Error setting StreamReadConstraints: {0}. Possibly not Jackson 2.18?
error.modules.not.loaded=Jackson modules could not be loaded: {0}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.StreamReadConstraints;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.exc.StreamConstraintsException;
import com.fasterxml.jackson.core.json.PackageVersion;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializable;
import com.fasterxml.jackson.databind.Module;
Expand Down Expand Up @@ -134,15 +136,37 @@ void testConstraintOnClient(WebTarget target, int expectedLength) {
}
}


@Test
void testMatchingVersion() {
final Version coreVersion = PackageVersion.VERSION;
final Version jerseyVersion = org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.PackageVersion.VERSION;

StringBuilder message = new StringBuilder();
message.append("Dependency Jackson Version is ")
.append(coreVersion.getMajorVersion())
.append(".")
.append(coreVersion.getMinorVersion());
message.append("\n Repackaged Jackson Version is ")
.append(jerseyVersion.getMajorVersion())
.append(".")
.append(jerseyVersion.getMinorVersion());

Assertions.assertEquals(coreVersion.getMajorVersion(), jerseyVersion.getMajorVersion(), message.toString());
Assertions.assertEquals(coreVersion.getMinorVersion(), jerseyVersion.getMinorVersion(), message.toString());
Assertions.assertEquals(coreVersion.getMajorVersion(), 2,
"update " + DefaultJacksonJaxbJsonProvider.class.getName()
+ " updateFactoryConstraints method to support version " + coreVersion.getMajorVersion());
}

@Test
void testStreamReadConstraintsMethods() {
String message = "There are additional methods in Jackson's StreamReaderConstraints.Builder."
+ " Please update the code in " + DefaultJacksonJaxbJsonProvider.class.getName()
+ " updateFactoryConstraints method";
Method[] method = StreamReadConstraints.Builder.class.getDeclaredMethods();
Assertions.assertEquals(6, method.length, message); // five setMax... + build() methods
// 2.17 : five setMax... + build() methods
// 2.18 : six setMax... + build() methods
Assertions.assertEquals(7, method.length, message);
}

@Path("len")
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,7 @@
<xmlunit.version>2.10.0</xmlunit.version>
<httpclient.version>4.5.14</httpclient.version>
<httpclient5.version>5.3.1</httpclient5.version>
<jackson.version>2.17.2</jackson.version>
<jackson.version>2.18.0</jackson.version>
<jackson1.version>1.9.13</jackson1.version>
<javassist.version>3.30.2-GA</javassist.version>
<jersey1.version>1.19.3</jersey1.version>
Expand Down

0 comments on commit ff5f5a8

Please sign in to comment.