Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ NOTE: Jackson 3.x components rely on 2.x annotations; there are no separate

#314: Add `JsonInclude.Value` convenience constants
(contributed by @runeflobakk)
#316: Make `JsonFormat.Features` java.io.Serializable
(requested by @tiger9800)

2.20 (28-Aug-2025)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,10 @@ public enum Feature {
* @since 2.6
*/
public static class Features
implements java.io.Serializable // @since 2.21
{
private static final long serialVersionUID = 1L;

private final int _enabled, _disabled;

private final static Features EMPTY = new Features(0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
*
* @since 2.12
*/
public static class Value implements JacksonAnnotationValue<JsonIncludeProperties>, java.io.Serializable
public static class Value implements JacksonAnnotationValue<JsonIncludeProperties>,
java.io.Serializable
{
private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.fasterxml.jackson.annotation;

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

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.UncheckedIOException;

abstract class AnnotationTestUtil {
/*
/**********************************************************
/* 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.jupiter.api.Assertions.*;

public class JacksonInjectTest
extends AnnotationTestUtil
{
private final static class Bogus {
@JacksonInject(value="inject", useInput=OptBoolean.FALSE,
Expand Down Expand Up @@ -47,6 +48,11 @@ public void testFromAnnotation() throws Exception
assertFalse(v.equals(EMPTY));
assertFalse(EMPTY.equals(v));

// Verify JDK serializability
byte[] b = jdkSerialize(v);
JacksonInject.Value v2 = jdkDeserialize(b);
assertEquals(v, v2);

JacksonInject ann2 = Bogus.class.getField("vanilla").getAnnotation(JacksonInject.class);
v = JacksonInject.Value.from(ann2);
assertEquals(JacksonInject.Value.construct(null, null, null), v,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
* Tests to verify that it is possibly to merge {@link JsonFormat.Value}
* instances for overrides.
*/
public class FormatTest
public class JsonFormatTest
extends AnnotationTestUtil
{
private final JsonFormat.Value EMPTY = JsonFormat.Value.empty();

Expand Down Expand Up @@ -71,15 +72,22 @@ public void testToString() {
@Test
public void testFromAnnotation()
{
// Trivial case first:
assertSame(EMPTY, JsonFormat.Value.from(null));

// then real one
JsonFormat ann = Bogus.class.getAnnotation(JsonFormat.class);
JsonFormat.Value v = JsonFormat.Value.from(ann);
assertEquals("xyz", v.getPattern());
assertEquals(JsonFormat.Shape.BOOLEAN, v.getShape());
// note: since it's not valid, should not try access as real thing
assertEquals("bogus", v.timeZoneAsString());

// also:
assertSame(EMPTY, JsonFormat.Value.from(null));
// [annotations#316]: let's also verify JDK serializability
byte[] b = jdkSerialize(v);
JsonFormat.Value v2 = jdkDeserialize(b);

assertEquals(v, v2);
}

@Test
Expand Down