Skip to content

Commit

Permalink
Merge branch 'master' into tatu/3.0/1484-mapper-feat-default-view-inc…
Browse files Browse the repository at this point in the history
…l-to-false
  • Loading branch information
cowtowncoder authored Jan 16, 2025
2 parents 842579c + b7ce302 commit 9e935e2
Show file tree
Hide file tree
Showing 48 changed files with 67 additions and 353 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@
</dependency>

<!-- Test dependencies -->

<!-- 13-Jan-2025, tatu: Use the new (in 3.0) shared core test-jar
for some shared test functionality.
-->
<dependency>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version.core}</version>
<classifier>tests</classifier>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
12 changes: 10 additions & 2 deletions src/test/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jackson 3.x module-info for Tests
// Jackson 3.x module-info for jackson-databind Tests
module tools.jackson.databind
{
requires java.desktop;
Expand All @@ -14,6 +14,15 @@

// // Actual Test dependencies

// Shared Jackson test functionality

// 15-Jan-2025, tatu: missing module-info for `tools.jackson.core` can't yet add
// (but will be included in Class path just not Module path)
//
//requires tools.jackson.core.testutil;

// Test frameworks, libraries:

// Guava testlib needed by CLMH tests, alas; brings in junit4
requires guava.testlib;
// JUnit4 should NOT be needed but is transitively required
Expand Down Expand Up @@ -86,7 +95,6 @@
opens tools.jackson.databind.ser.filter;
opens tools.jackson.databind.seq;
opens tools.jackson.databind.struct;
opens tools.jackson.databind.testutil.failure;
opens tools.jackson.databind.tofix;
opens tools.jackson.databind.util.internal;
opens tools.jackson.databind.views;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public QName deserialize(JsonParser p, DeserializationContext ctxt)
if (!p.hasToken(JsonToken.VALUE_STRING)) {
throw new IllegalArgumentException("Unexpected token "+p.currentToken());
}
return QName.valueOf(p.getText());
return QName.valueOf(p.getString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import org.junit.jupiter.api.Test;

import tools.jackson.core.testutil.failure.JacksonTestFailureExpected;

import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.testutil.DatabindTestUtil;
import tools.jackson.databind.testutil.failure.JacksonTestFailureExpected;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -14,7 +15,6 @@
public class DuplicatePropertyDeserializationRecord4690Test
extends DatabindTestUtil
{

record MyRecord(String first) { }

private final ObjectMapper mapper = newJsonMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import java.util.Collections;

import org.junit.jupiter.api.Test;
import tools.jackson.core.testutil.failure.JacksonTestFailureExpected;

import tools.jackson.databind.*;
import tools.jackson.databind.testutil.DatabindTestUtil;
import tools.jackson.databind.testutil.failure.JacksonTestFailureExpected;

import static org.junit.jupiter.api.Assertions.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import org.junit.jupiter.api.Test;

import tools.jackson.core.testutil.failure.JacksonTestFailureExpected;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonIncludeProperties;

import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.testutil.DatabindTestUtil;
import tools.jackson.databind.testutil.failure.JacksonTestFailureExpected;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand Down
100 changes: 2 additions & 98 deletions src/test/java/tools/jackson/databind/testutil/DatabindTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import java.io.*;
import java.lang.annotation.*;
import java.nio.charset.StandardCharsets;
import java.util.*;

import tools.jackson.core.*;
import tools.jackson.core.json.JsonFactory;
import tools.jackson.core.testutil.JacksonTestUtilBase;
import tools.jackson.databind.*;
import tools.jackson.databind.cfg.MapperConfig;
import tools.jackson.databind.introspect.AnnotatedMember;
Expand All @@ -22,6 +22,7 @@
* as part of JUnit 5 migration.
*/
public class DatabindTestUtil
extends JacksonTestUtilBase
{
// @since 2.18
// Helper annotation to work around lack of implicit name access with Jackson 2.x
Expand Down Expand Up @@ -407,37 +408,12 @@ protected String serializeAsString(Object value)
return serializeAsString(sharedMapper(), value);
}

/*
/**********************************************************************
/* Encoding or String representations
/**********************************************************************
*/

public static String a2q(String json) {
return json.replace("'", "\"");
}

public static String q(String str) {
return '"'+str+'"';
}

public static byte[] utf8Bytes(String str) {
return str.getBytes(StandardCharsets.UTF_8);
}

/*
/**********************************************************************
/* Additional assertion methods
/**********************************************************************
*/

public static void assertToken(JsonToken expToken, JsonToken actToken)
{
if (actToken != expToken) {
fail("Expected token "+expToken+", current token "+actToken);
}
}

public static void assertValidLocation(TokenStreamLocation location) {
assertNotNull(location, "Should have non-null location");
assertTrue(location.getLineNr() > 0, "Should have positive line number");
Expand Down Expand Up @@ -478,78 +454,6 @@ protected void assertStandardEquals(Object o)
o.hashCode();
}

/**
* @param e Exception to check
* @param anyMatches Array of Strings of which AT LEAST ONE ("any") has to be included
* in {@code e.getMessage()} -- using case-INSENSITIVE comparison
*/
public static void verifyException(Throwable e, String... anyMatches)
{
String msg = e.getMessage();
String lmsg = (msg == null) ? "" : msg.toLowerCase();
for (String match : anyMatches) {
String lmatch = match.toLowerCase();
if (lmsg.contains(lmatch)) {
return;
}
}
fail("Expected an exception with one of substrings ("
+ Arrays.asList(anyMatches)+"): got one (of type "+e.getClass().getName()
+") with message \""+msg+"\"");
}

/**
* Method that gets textual contents of the current token using
* available methods, and ensures results are consistent, before
* returning them
*/
protected static String getAndVerifyText(JsonParser jp)
{
// Ok, let's verify other accessors
int actLen = jp.getStringLength();
char[] ch = jp.getStringCharacters();
String str2 = new String(ch, jp.getStringOffset(), actLen);
String str = jp.getString();

if (str.length() != actLen) {
fail("Internal problem (jp.token == "+jp.currentToken()+"): jp.getText().length() ['"+str+"'] == "+str.length()+"; jp.getTextLength() == "+actLen);
}
assertEquals(str, str2, "String access via getText(), getTextXxx() must be the same");

return str;
}

/*
/**********************************************************
/* JDK ser/deser
/**********************************************************
*/

public static byte[] jdkSerialize(Object o)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream(2000);
try (ObjectOutputStream obOut = new ObjectOutputStream(bytes)) {
obOut.writeObject(o);
obOut.close();
return bytes.toByteArray();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

@SuppressWarnings("unchecked")
public static <T> T jdkDeserialize(byte[] raw)
{
try (ObjectInputStream objIn = new ObjectInputStream(new ByteArrayInputStream(raw))) {
return (T) objIn.readObject();
} catch (ClassNotFoundException e) {
fail("Missing class: "+e.getMessage());
return null;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

/*
/**********************************************************************
/* Helper methods, other
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9e935e2

Please sign in to comment.