Skip to content

Commit

Permalink
Implement #103, binary-data capability introspection
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 14, 2013
1 parent 711971d commit b883544
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ New minor version.
current field name
(reported by Sam R)
#98: Improve handling of failures for `BigDecimal`, for "NaN" (and infinity)
#103: Add `JsonFactory.canHandleBinaryNatively`, `JsonGenerator.canWriteBinaryNatively`
to let databind module detect level of support for binary data.
- Improve `DefaultPrettyPrinter`, `Lf2SpacesIndenter` (from databind #276)
- Add `JsonGenerator.canOmitFields()` method to support discovery of
positional formats, needed for handling of filtering for CSV
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/com/fasterxml/jackson/core/JsonFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,23 @@ protected Object readResolve() {
public boolean requiresPropertyOrdering() {
return false;
}


/**
* Introspection method that higher-level functionality may call
* to see whether underlying data format can read and write binary
* data natively; that is, embeded it as-is without using encodings
* such as Base64.
*<p>
* Default implementation returns <code>false</code> as JSON does not
* support native access: all binary content must use Base64 encoding.
* Most binary formats (like Smile and Avro) support native binary content.
*
* @since 2.3
*/
public boolean canHandleBinaryNatively(FormatSchema schema) {
return false;
}

/*
/**********************************************************
/* Format detection functionality (since 1.8)
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/fasterxml/jackson/core/JsonGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,20 @@ public boolean canWriteTypeId() {
return false;
}

/**
* Introspection method that may be called to see if the underlying
* data format supports "native" binary data; that is, an efficient
* output of binary content without encoding.
*<p>
* Default implementation returns false; overridden by data formats
* that do support native binary content.
*
* @since 2.3
*/
public boolean canWriteBinaryNatively() {
return false;
}

/**
* Introspection method to call to check whether it is ok to omit
* writing of Object fields or not. Most formats do allow omission,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public boolean canWriteObjectId() {
return delegate.canWriteObjectId();
}

@Override
public boolean canWriteBinaryNatively() {
return delegate.canWriteBinaryNatively();
}

@Override
public boolean canOmitFields() {
return delegate.canOmitFields();
Expand Down

0 comments on commit b883544

Please sign in to comment.