Skip to content

Commit 2e262b9

Browse files
committed
Baseline work for #196, generic support for format-specific features
1 parent 88c296c commit 2e262b9

File tree

5 files changed

+172
-5
lines changed

5 files changed

+172
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fasterxml.jackson.core;
2+
3+
/**
4+
* Marker interface that is to be implemented by data format - specific features.
5+
* Interface used since Java Enums can not extend classes or other Enums, but
6+
* they can implement interfaces; and as such we may be able to use limited
7+
* amount of generic functionality.
8+
*<p>
9+
* Note that this type is only implemented by non-JSON formats:
10+
* types {@link JsonParser.Feature} and {@link JsonGenerator.Feature} do NOT
11+
* implement it. This is to make it easier to avoid ambiguity with method
12+
* calls.
13+
*
14+
* @since 2.6 (to be fully used in 2.7 and beyond)
15+
*/
16+
public interface FormatFeature
17+
{
18+
/**
19+
* Accessor for checking whether this feature is enabled by default.
20+
*/
21+
public boolean enabledByDefault();
22+
23+
/**
24+
* Returns bit mask for this feature instance; must be a single bit,
25+
* that is of form <code>(1 << N)</code>
26+
*/
27+
public int getMask();
28+
29+
/**
30+
* Convenience method for checking whether feature is enabled in given bitmask
31+
*/
32+
public boolean enabledIn(int flags);
33+
}

src/main/java/com/fasterxml/jackson/core/JsonFactory.java

+27-2
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,31 @@ protected Object readResolve() {
413413
* @since 2.4
414414
*/
415415
public boolean canUseCharArrays() { return true; }
416-
416+
417+
/**
418+
* Method for accessing kind of {@link FormatFeature} that a parser
419+
* {@link JsonParser} produced by this factory would accept, if any;
420+
* <code>null</code> returned if none.
421+
*
422+
* @since 2.6
423+
*/
424+
public Class<? extends FormatFeature> getFormatReadFeatureType() {
425+
return null;
426+
}
427+
428+
/**
429+
* Method for accessing kind of {@link FormatFeature} that a parser
430+
* {@link JsonGenerator} produced by this factory would accept, if any;
431+
* <code>null</code> returned if none.
432+
*
433+
* @since 2.6
434+
*/
435+
public Class<? extends FormatFeature> getFormatWriteFeatureType() {
436+
return null;
437+
}
417438
/*
418439
/**********************************************************
419-
/* Format detection functionality (since 1.8)
440+
/* Format detection functionality
420441
/**********************************************************
421442
*/
422443

@@ -454,6 +475,10 @@ public String getFormatName()
454475
return null;
455476
}
456477

478+
/**
479+
* Convenience method for trying to determine whether input via given accessor
480+
* is of format type supported by this factory.
481+
*/
457482
public MatchStrength hasFormat(InputAccessor acc) throws IOException
458483
{
459484
// since we can't keep this abstract, only implement for "vanilla" instance

src/main/java/com/fasterxml/jackson/core/JsonGenerator.java

+60-2
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,10 @@ public final JsonGenerator configure(Feature f, boolean state) {
305305

306306

307307
/**
308-
* Bulk access method for getting state of all standard {@link Feature}s.
308+
* Bulk access method for getting state of all standard (non-dataformat-specific)
309+
* {@link JsonGenerator.Feature}s.
309310
*
310-
* @return Bit mask that defines current states of all standard {@link Feature}s.
311+
* @return Bit mask that defines current states of all standard {@link JsonGenerator.Feature}s.
311312
*
312313
* @since 2.3
313314
*/
@@ -325,6 +326,60 @@ public final JsonGenerator configure(Feature f, boolean state) {
325326
*/
326327
public abstract JsonGenerator setFeatureMask(int values);
327328

329+
/**
330+
* Bulk set method for (re)setting states of features specified by <code>mask</code>.
331+
* Functionally equivalent to
332+
*<code>
333+
* int oldState = getFeatureMask();
334+
* int newState = (oldState & ~mask) | (values & mask);
335+
* setFeatureMask(newState);
336+
*</code>
337+
*
338+
* @param values Bit mask of set/clear state for features to change
339+
* @param mask Bit mask of features to change
340+
*
341+
* @since 2.6
342+
*/
343+
public JsonGenerator overrideStdFeatures(int values, int mask) {
344+
int oldState = getFeatureMask();
345+
int newState = (oldState & ~mask) | (values & mask);
346+
return setFeatureMask(newState);
347+
}
348+
349+
/**
350+
* Bulk access method for getting state of all {@link FormatFeature}s, format-specific
351+
* on/off configuration settings.
352+
*
353+
* @return Bit mask that defines current states of all standard {@link FormatFeature}s.
354+
*
355+
* @since 2.6
356+
*/
357+
public int getFormatFeatures() {
358+
return 0;
359+
}
360+
361+
/**
362+
* Bulk set method for (re)setting states of {@link FormatFeature}s,
363+
* by specifying values (set / clear) along with a mask, to determine
364+
* which features to change, if any.
365+
*<p>
366+
* Default implementation will simply throw an exception to indicate that
367+
* the generator implementation does not support any {@link FormatFeature}s.
368+
*
369+
* @param values Bit mask of set/clear state for features to change
370+
* @param mask Bit mask of features to change
371+
*
372+
* @since 2.6
373+
*/
374+
public JsonGenerator overrideFormatFeatures(int values, int mask) {
375+
throw new IllegalArgumentException("No FormatFeatures defined for generator of type "+getClass().getName());
376+
/*
377+
int oldState = getFeatureMask();
378+
int newState = (oldState & ~mask) | (values & mask);
379+
return setFeatureMask(newState);
380+
*/
381+
}
382+
328383
/*
329384
/**********************************************************
330385
/* Public API, Schema configuration
@@ -509,9 +564,12 @@ public Object getOutputTarget() {
509564
*
510565
* @since 2.6
511566
*/
567+
public abstract int getOutputBuffered();
568+
/*
512569
public int getOutputBuffered() {
513570
return -1;
514571
}
572+
*/
515573

516574
/**
517575
* Helper method, usually equivalent to:

src/main/java/com/fasterxml/jackson/core/JsonParser.java

+51
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,58 @@ public JsonParser setFeatureMask(int mask) {
529529
_features = mask;
530530
return this;
531531
}
532+
533+
/**
534+
* Bulk set method for (re)setting states of features specified by <code>mask</code>.
535+
* Functionally equivalent to
536+
*<code>
537+
* int oldState = getFeatureMask();
538+
* int newState = (oldState & ~mask) | (values & mask);
539+
* setFeatureMask(newState);
540+
*</code>
541+
*
542+
* @param values Bit mask of set/clear state for features to change
543+
* @param mask Bit mask of features to change
544+
*
545+
* @since 2.6
546+
*/
547+
public JsonParser overrideStdFeatures(int values, int mask) {
548+
_features = (_features & ~mask) | (values & mask);
549+
return this;
550+
}
551+
552+
/**
553+
* Bulk access method for getting state of all {@link FormatFeature}s, format-specific
554+
* on/off configuration settings.
555+
*
556+
* @return Bit mask that defines current states of all standard {@link FormatFeature}s.
557+
*
558+
* @since 2.6
559+
*/
560+
public int getFormatFeatures() {
561+
return 0;
562+
}
532563

564+
/**
565+
* Bulk set method for (re)setting states of {@link FormatFeature}s,
566+
* by specifying values (set / clear) along with a mask, to determine
567+
* which features to change, if any.
568+
*<p>
569+
* Default implementation will simply throw an exception to indicate that
570+
* the generator implementation does not support any {@link FormatFeature}s.
571+
*
572+
* @param values Bit mask of set/clear state for features to change
573+
* @param mask Bit mask of features to change
574+
*
575+
* @since 2.6
576+
*/
577+
public JsonParser overrideFormatFeatures(int values, int mask) {
578+
throw new IllegalArgumentException("No FormatFeatures defined for parser of type "+getClass().getName());
579+
/*
580+
_formatFeatures = (_formatFeatures & ~mask) | (values & mask);
581+
*/
582+
}
583+
533584
/*
534585
/**********************************************************
535586
/* Public API, traversal

src/main/java/com/fasterxml/jackson/core/util/VersionUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public static Version mavenVersionFor(ClassLoader cl, String groupId, String art
135135
}
136136

137137
/**
138-
* Method used by {@link PackageVersion} to decode version injected by Maven build.
138+
* Method used by <code>PackageVersion</code> classes to decode version injected by Maven build.
139139
*/
140140
public static Version parseVersion(String s, String groupId, String artifactId)
141141
{

0 commit comments

Comments
 (0)