Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9744808
start of move
pjfanning Mar 18, 2025
0141457
tests
pjfanning Mar 18, 2025
b25ee25
move javatimefeature enable to mapperbuilder
pjfanning Mar 18, 2025
615f6f2
accidental edit (fixed)
pjfanning Mar 18, 2025
e5b0263
auto-enable JavaTimeModule - breaks a few tests
pjfanning Mar 18, 2025
e586ec5
remove code that warns if java.time classes are used but module is no…
pjfanning Mar 18, 2025
70d3194
remove JavaTimeModule
pjfanning Mar 18, 2025
d47a0e9
fix test - no longer fails because java.time is now supported out of …
pjfanning Mar 18, 2025
c78b6cb
Update POJONodeTest.java
pjfanning Mar 18, 2025
67e4154
make method private - class is final anyway
pjfanning Mar 18, 2025
30b97d8
Update module-info.java
pjfanning Mar 18, 2025
1393821
change package name
pjfanning Mar 19, 2025
27ef8b7
Merge branch 'master' into datetime
cowtowncoder Mar 20, 2025
0dd3dfc
Merge branch 'master' into datetime
cowtowncoder Mar 24, 2025
1be24ec
Merge branch 'master' into datetime
cowtowncoder Mar 26, 2025
27bafa4
Merge branch 'master' into datetime
cowtowncoder Mar 26, 2025
e8c7c99
Merge branch 'master' into datetime
cowtowncoder Mar 29, 2025
3d39a7f
Merge branch 'master' into datetime
cowtowncoder Apr 3, 2025
f4325b7
Merge https://github.com/FasterXML/jackson-modules-java8/issues/364 c…
cowtowncoder Apr 4, 2025
6f43389
Minor Javadoc improvements
cowtowncoder Apr 4, 2025
d6d8d04
Start conversion to make `JavaTimeFeature` be accessed via `DatatypeF…
cowtowncoder Apr 4, 2025
0f8a890
Bit of refactoring wrt JavaTimeFeature
cowtowncoder Apr 4, 2025
6432627
Minor refactoring
cowtowncoder Apr 4, 2025
6e25e80
Refactoring: change "ext.datetime" to "ext.javatime" wrt supported AP…
cowtowncoder Apr 4, 2025
765ca83
Minor javadoc improvements
cowtowncoder Apr 4, 2025
c5ffdd8
Rename JavaTimeFeature as DateTimeFeature for use with java.util/Joda…
cowtowncoder Apr 4, 2025
53303b9
Minor reordering
cowtowncoder Apr 4, 2025
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
5 changes: 5 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
exports tools.jackson.databind.deser.std;
exports tools.jackson.databind.exc;
exports tools.jackson.databind.ext;
exports tools.jackson.databind.ext.datetime;
exports tools.jackson.databind.ext.datetime.deser;
exports tools.jackson.databind.ext.datetime.deser.key;
exports tools.jackson.databind.ext.datetime.ser;
exports tools.jackson.databind.ext.datetime.ser.key;
exports tools.jackson.databind.ext.jdk8;
// Needed by Ion module for SqlDate deserializer:
exports tools.jackson.databind.ext.sql;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/tools/jackson/databind/JacksonModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import java.util.function.UnaryOperator;

import tools.jackson.core.*;
import tools.jackson.core.util.JacksonFeatureSet;
import tools.jackson.databind.cfg.MapperBuilder;
import tools.jackson.databind.cfg.MutableConfigOverride;
import tools.jackson.databind.ext.datetime.JavaTimeFeature;
import tools.jackson.databind.deser.*;
import tools.jackson.databind.jsontype.NamedType;
import tools.jackson.databind.ser.Serializers;
Expand Down Expand Up @@ -146,6 +148,9 @@ public static interface SetupContext
public boolean isEnabled(TokenStreamFactory.Feature f);
public boolean isEnabled(StreamReadFeature f);
public boolean isEnabled(StreamWriteFeature f);
public boolean isEnabled(JavaTimeFeature f);

public JacksonFeatureSet<JavaTimeFeature> getJavaTimeFeatures();

/*
/******************************************************************
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/tools/jackson/databind/cfg/MapperBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@

import tools.jackson.core.*;
import tools.jackson.core.util.DefaultPrettyPrinter;
import tools.jackson.core.util.JacksonFeatureSet;
import tools.jackson.core.util.Snapshottable;
import tools.jackson.databind.*;
import tools.jackson.databind.ext.datetime.JavaTimeFeature;
import tools.jackson.databind.ext.datetime.JavaTimeInitializer;
import tools.jackson.databind.deser.*;
import tools.jackson.databind.introspect.*;
import tools.jackson.databind.jsontype.*;
Expand Down Expand Up @@ -241,6 +244,12 @@ public abstract class MapperBuilder<M extends ObjectMapper,
*/
protected int _formatWriteFeatures;

/**
* States of {@link JavaTimeFeature}s to enable/disable.
*/
protected JacksonFeatureSet<JavaTimeFeature> _javaTimeFeatures =
Copy link
Member

Choose a reason for hiding this comment

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

Ahhhh. Ok, here's something we'll need to change: new JavaTimeFeature (or eventual DateTimeFeature) can and should be added as 3rd thing in DatatypeFeatures (along with EnumFeature and JsonNodeFeature) -- it's designed to be extended.

I can do that tomorrow.

JacksonFeatureSet.fromDefaults(JavaTimeFeature.values());

/*
/**********************************************************************
/* Transient state
Expand Down Expand Up @@ -419,8 +428,9 @@ public MapperBuilderState saveStateApplyModules()
{
if (_savedState == null) {
_savedState = _saveState();
ModuleContextBase ctxt = _constructModuleContext();
JavaTimeInitializer.getInstance().setupModule(ctxt);
if (_modules != null) {
ModuleContextBase ctxt = _constructModuleContext();
_modules.values().forEach(m -> m.setupModule(ctxt));
// and since context may buffer some changes, ensure those are flushed:
ctxt.applyChanges(this);
Expand Down Expand Up @@ -493,6 +503,14 @@ public boolean isEnabled(StreamWriteFeature f) {
return f.enabledIn(_streamWriteFeatures);
}

public boolean isEnabled(JavaTimeFeature f) {
return _javaTimeFeatures.isEnabled(f);
}

public JacksonFeatureSet<JavaTimeFeature> getJavaTimeFeatures() {
return _javaTimeFeatures;
}

public DatatypeFeatures datatypeFeatures() {
return _datatypeFeatures;
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/tools/jackson/databind/cfg/ModuleContextBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import java.util.function.UnaryOperator;

import tools.jackson.core.*;
import tools.jackson.core.util.JacksonFeatureSet;
import tools.jackson.databind.*;
import tools.jackson.databind.JacksonModule.SetupContext;
import tools.jackson.databind.ext.datetime.JavaTimeFeature;
import tools.jackson.databind.deser.*;
import tools.jackson.databind.jsontype.NamedType;
import tools.jackson.databind.ser.SerializerFactory;
Expand Down Expand Up @@ -125,6 +127,16 @@ public boolean isEnabled(StreamWriteFeature f) {
return _builder.isEnabled(f);
}

@Override
public boolean isEnabled(JavaTimeFeature f) {
return _builder.isEnabled(f);
}

@Override
public JacksonFeatureSet<JavaTimeFeature> getJavaTimeFeatures() {
return _builder.getJavaTimeFeatures();
}

/*
/**********************************************************************
/* Mutators for adding deserializers, related
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package tools.jackson.databind.ext.datetime;

import tools.jackson.core.util.JacksonFeature;

/**
* Configurable on/off features for Java 8 Date/Time module ({@link JavaTimeInitializer}).
*
* @since 2.16
*/
public enum JavaTimeFeature implements JacksonFeature
Copy link
Member

Choose a reason for hiding this comment

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

If possible, I think we should actually change the idea here to create new DateTimeFeature that should ideally control ALL date/time handling (mostly concerning then old java.util Date/Calendar and Joda date/time).

It would contain entries we have here, initially, but then see if we could move existing DeserializationFeatures/SerializationFeatures that are date/time specific into this new enum.

This would then be a building block for

https://github.com/FasterXML/jackson-future-ideas/wiki/JSTEP-5

Finally, renamed DateTimeFeature should go in tools.jackson.databind.cfg along with existing EnumFeature and JsonNodeFeature.

{
/**
* Feature that determines whether {@link java.time.ZoneId} is normalized
* (via call to {@code java.time.ZoneId#normalized()}) when deserializing
* types like {@link java.time.ZonedDateTime}.
*<p>
* Default setting is enabled, for backwards-compatibility with
* Jackson 2.15.
*/
NORMALIZE_DESERIALIZED_ZONE_ID(true),

/**
* Feature that determines whether the {@link java.util.TimeZone} of the
* {@link tools.jackson.databind.DeserializationContext} is used
* when leniently deserializing {@link java.time.LocalDate} or
* {@link java.time.LocalDateTime} from the UTC/ISO instant format.
* <p>
* Default setting is disabled, for backwards-compatibility with
* Jackson 2.18.
*
* @since 2.19
*/
USE_TIME_ZONE_FOR_LENIENT_DATE_PARSING(false),

/**
* Feature that controls whether stringified numbers (Strings that without
* quotes would be legal JSON Numbers) may be interpreted as
* timestamps (enabled) or not (disabled), in case where there is an
* explicitly defined pattern ({@code DateTimeFormatter}) for value.
* <p>
* Note that when the default pattern is used (no custom pattern defined),
* stringified numbers are always accepted as timestamps regardless of
* this feature.
*/
ALWAYS_ALLOW_STRINGIFIED_DATE_TIMESTAMPS(false),

/**
* Feature that determines whether {@link java.time.Month} is serialized
* and deserialized as using a zero-based index (FALSE) or a one-based index (TRUE).
* For example, "1" would be serialized/deserialized as Month.JANUARY if TRUE and Month.FEBRUARY if FALSE.
*<p>
* Default setting is false, meaning that Month is serialized/deserialized as a zero-based index.
*/
ONE_BASED_MONTHS(false)
;

/**
* Whether feature is enabled or disabled by default.
*/
private final boolean _defaultState;

private final int _mask;

JavaTimeFeature(boolean enabledByDefault) {
_defaultState = enabledByDefault;
_mask = (1 << ordinal());
}

@Override
public boolean enabledByDefault() { return _defaultState; }

@Override
public boolean enabledIn(int flags) { return (flags & _mask) != 0; }

@Override
public int getMask() { return _mask; }
}
Loading