Skip to content

Conversation

@tiger9800
Copy link
Contributor

Add support for radices using the added to JsonFormat radix attribute in FasterXML/jackson-annotations#321. The initial work for the PR was done in issue #5317, and the original request was #221.

import tools.jackson.databind.util.ClassUtil;
import tools.jackson.databind.util.Converter;

import static com.fasterxml.jackson.annotation.JsonFormat.DEFAULT_RADIX;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

}

JsonFormat.Value formatValue = EMPTY_FORMAT;
if (v0 != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How could this be null when it is assigned on line 61?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}

@Override
public JsonFormat.Value findPropertyFormat(MapperConfig<?> config, Class<?> baseType)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am bit confused here -- why are changes needed? Shouldn't override handling work for radix just like all other properties? If not, why not (are fixes needed in jackson-annotations?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is to consider default format out of ConfigOverrides which has the lowest precedence. This way we can make the a given radix apply to all integral types. This is what you meant here, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also added a test for this behavior DifferentRadixNumberFormatTest#testIntSerializedAsHexStringWithDefaultRadix

JsonFormat.Value v2 = null;
AnnotationIntrospector intr = config.getAnnotationIntrospector();
if (intr != null) {
AnnotatedMember member = getMember();
Copy link
Member

@cowtowncoder cowtowncoder Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we mixing in member annotations now -- this changes semantics of the method.

EDIT: never mind, that was done via findFormatOverrides() which does about same. But maybe call that method instead of inlining the logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Do not remember why I inlined in #5317

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants