This is an automated email from the ASF dual-hosted git repository. mblow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
commit 111dc14ca1bf4c28fa1fbd609b206c4391269f00 Author: Ian Maxon <ima...@apache.org> AuthorDate: Tue Feb 5 22:52:04 2019 -0800 [NO ISSUE] Remove un-neccessary Jackson printer During the org.json change we needed this to avoid changing many test files but it is not really worth maintaining anymore. Change-Id: I465d4f0d4352f2bd7eb3ec40062a998de578d8c6 Reviewed-on: https://asterix-gerrit.ics.uci.edu/3150 Reviewed-by: Michael Blow <mb...@apache.org> Integration-Tests: Michael Blow <mb...@apache.org> Tested-by: Michael Blow <mb...@apache.org> --- .../asterix/test/common/ResultExtractor.java | 7 +- .../test/common/SingleLinePrettyPrinter.java | 405 --------------------- .../results/json/int01-cleanjson/int01.1.json | 3 +- .../results/json/int01-losslessjson/int01.1.json | 9 +- .../json/issue-ASTERIXDB-1165/nullablefield.1.json | 3 +- .../results/numeric/non-finite/non-finite.1.json | 7 +- 6 files changed, 17 insertions(+), 417 deletions(-) diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/ResultExtractor.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/ResultExtractor.java index 412cf03..37e1213 100644 --- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/ResultExtractor.java +++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/ResultExtractor.java @@ -31,7 +31,7 @@ import org.apache.commons.io.IOUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.fasterxml.jackson.core.PrettyPrinter; +import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -109,7 +109,6 @@ public class ResultExtractor { private static InputStream extract(InputStream resultStream, EnumSet<ResultField> resultFields) throws Exception { final String resultStr = IOUtils.toString(resultStream, Charset.defaultCharset()); - final PrettyPrinter singleLine = new SingleLinePrettyPrinter(); final ObjectNode result = OBJECT_MAPPER.readValue(resultStr, ObjectNode.class); LOGGER.debug("+++++++\n" + result + "\n+++++++\n"); @@ -136,9 +135,9 @@ public class ResultExtractor { resultBuilder.append(fieldValue.get(0).asText()); } else { ObjectMapper omm = new ObjectMapper(); - omm.setDefaultPrettyPrinter(singleLine); omm.enable(SerializationFeature.INDENT_OUTPUT); - resultBuilder.append(omm.writer(singleLine).writeValueAsString(fieldValue)); + resultBuilder + .append(omm.writer(new DefaultPrettyPrinter()).writeValueAsString(fieldValue)); } } else { resultBuilder.append(OBJECT_MAPPER.writeValueAsString(fieldValue)); diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/SingleLinePrettyPrinter.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/SingleLinePrettyPrinter.java deleted file mode 100644 index 2932ca4..0000000 --- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/SingleLinePrettyPrinter.java +++ /dev/null @@ -1,405 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.asterix.test.common; - -import java.io.IOException; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.PrettyPrinter; -import com.fasterxml.jackson.core.SerializableString; -import com.fasterxml.jackson.core.io.SerializedString; -import com.fasterxml.jackson.core.util.Instantiatable; - -/** - * Default {@link PrettyPrinter} implementation that uses 2-space - * indentation with platform-default linefeeds. - * Usually this class is not instantiated directly, but instead - * method {@link JsonGenerator#useSingleLinePrettyPrinter} is - * used, which will use an instance of this class for operation. - */ -@SuppressWarnings("serial") -public class SingleLinePrettyPrinter - implements PrettyPrinter, Instantiatable<SingleLinePrettyPrinter>, java.io.Serializable { - private static final long serialVersionUID = 1; - - /** - * Constant that specifies default "root-level" separator to use between - * root values: a single space character. - * - * @since 2.1 - */ - public final static SerializedString DEFAULT_ROOT_VALUE_SEPARATOR = new SerializedString(" "); - - /** - * Interface that defines objects that can produce indentation used - * to separate object entries and array values. Indentation in this - * context just means insertion of white space, independent of whether - * linefeeds are output. - */ - public interface Indenter { - void writeIndentation(JsonGenerator jg, int level) throws IOException; - - /** - * @return True if indenter is considered inline (does not add linefeeds), - * false otherwise - */ - boolean isInline(); - } - - // // // Config, indentation - - /** - * By default, let's use only spaces to separate array values. - */ - protected Indenter _arrayIndenter = FixedSpaceIndenter.instance; - - /** - * By default, let's use linefeed-adding indenter for separate - * object entries. We'll further configure indenter to use - * system-specific linefeeds, and 2 spaces per level (as opposed to, - * say, single tabs) - */ - protected Indenter _objectIndenter = new FixedSpaceIndenter(); - - /** - * String printed between root-level values, if any. - */ - protected final SerializableString _rootSeparator; - - // // // Config, other white space configuration - - /** - * By default we will add spaces around colons used to - * separate object fields and values. - * If disabled, will not use spaces around colon. - */ - protected boolean _spacesInObjectEntries = true; - - // // // State: - - /** - * Number of open levels of nesting. Used to determine amount of - * indentation to use. - */ - protected transient int _nesting; - - /* - /********************************************************** - /* Life-cycle (construct, configure) - /********************************************************** - */ - - public SingleLinePrettyPrinter() { - this(DEFAULT_ROOT_VALUE_SEPARATOR); - } - - /** - * Constructor that specifies separator String to use between root values; - * if null, no separator is printed. - * <p> - * Note: simply constructs a {@link SerializedString} out of parameter, - * calls {@link #SingleLinePrettyPrinter(SerializableString)} - * - * @param rootSeparator - * @since 2.1 - */ - public SingleLinePrettyPrinter(String rootSeparator) { - this((rootSeparator == null) ? null : new SerializedString(rootSeparator)); - } - - /** - * Constructor that specifies separator String to use between root values; - * if null, no separator is printed. - * - * @param rootSeparator - * @since 2.1 - */ - public SingleLinePrettyPrinter(SerializableString rootSeparator) { - _rootSeparator = rootSeparator; - } - - public SingleLinePrettyPrinter(SingleLinePrettyPrinter base) { - this(base, base._rootSeparator); - } - - public SingleLinePrettyPrinter(SingleLinePrettyPrinter base, SerializableString rootSeparator) { - _arrayIndenter = base._arrayIndenter; - _objectIndenter = base._objectIndenter; - _spacesInObjectEntries = base._spacesInObjectEntries; - _nesting = base._nesting; - - _rootSeparator = rootSeparator; - } - - public SingleLinePrettyPrinter withRootSeparator(SerializableString rootSeparator) { - if (_rootSeparator == rootSeparator || (rootSeparator != null && rootSeparator.equals(_rootSeparator))) { - return this; - } - return new SingleLinePrettyPrinter(this, rootSeparator); - } - - /** - * @since 2.6.0 - */ - public SingleLinePrettyPrinter withRootSeparator(String rootSeparator) { - return withRootSeparator((rootSeparator == null) ? null : new SerializedString(rootSeparator)); - } - - public void indentArraysWith(Indenter i) { - _arrayIndenter = (i == null) ? NopIndenter.instance : i; - } - - public void indentObjectsWith(Indenter i) { - _objectIndenter = (i == null) ? NopIndenter.instance : i; - } - - /** - * @deprecated Since 2.3 use {@link #withSpacesInObjectEntries} and {@link #withoutSpacesInObjectEntries()} - */ - @Deprecated - public void spacesInObjectEntries(boolean b) { - _spacesInObjectEntries = b; - } - - /** - * @since 2.3 - */ - public SingleLinePrettyPrinter withArrayIndenter(Indenter i) { - if (i == null) { - i = NopIndenter.instance; - } - if (_arrayIndenter == i) { - return this; - } - SingleLinePrettyPrinter pp = new SingleLinePrettyPrinter(this); - pp._arrayIndenter = i; - return pp; - } - - /** - * @since 2.3 - */ - public SingleLinePrettyPrinter withObjectIndenter(Indenter i) { - if (i == null) { - i = NopIndenter.instance; - } - if (_objectIndenter == i) { - return this; - } - SingleLinePrettyPrinter pp = new SingleLinePrettyPrinter(this); - pp._objectIndenter = i; - return pp; - } - - /** - * "Mutant factory" method that will return a pretty printer instance - * that does use spaces inside object entries; if 'this' instance already - * does this, it is returned; if not, a new instance will be constructed - * and returned. - * - * @since 2.3 - */ - public SingleLinePrettyPrinter withSpacesInObjectEntries() { - return _withSpaces(true); - } - - /** - * "Mutant factory" method that will return a pretty printer instance - * that does not use spaces inside object entries; if 'this' instance already - * does this, it is returned; if not, a new instance will be constructed - * and returned. - * - * @since 2.3 - */ - public SingleLinePrettyPrinter withoutSpacesInObjectEntries() { - return _withSpaces(false); - } - - protected SingleLinePrettyPrinter _withSpaces(boolean state) { - if (_spacesInObjectEntries == state) { - return this; - } - SingleLinePrettyPrinter pp = new SingleLinePrettyPrinter(this); - pp._spacesInObjectEntries = state; - return pp; - } - - /* - /********************************************************** - /* Instantiatable impl - /********************************************************** - */ - - @Override - public SingleLinePrettyPrinter createInstance() { - return new SingleLinePrettyPrinter(this); - } - - /* - /********************************************************** - /* PrettyPrinter impl - /********************************************************** - */ - - @Override - public void writeRootValueSeparator(JsonGenerator jg) throws IOException { - if (_rootSeparator != null) { - jg.writeRaw(_rootSeparator); - } - } - - @Override - public void writeStartObject(JsonGenerator jg) throws IOException { - jg.writeRaw('{'); - ++_nesting; - } - - @Override - public void beforeObjectEntries(JsonGenerator jg) throws IOException { - _objectIndenter.writeIndentation(jg, _nesting); - } - - /** - * Method called after an object field has been output, but - * before the value is output. - * <p> - * Default handling (without pretty-printing) will output a single - * colon to separate the two. Pretty-printer is - * to output a colon as well, but can surround that with other - * (white-space) decoration. - */ - @Override - public void writeObjectFieldValueSeparator(JsonGenerator jg) throws IOException { - if (_spacesInObjectEntries) { - jg.writeRaw(": "); - } else { - jg.writeRaw(':'); - } - } - - /** - * Method called after an object entry (field:value) has been completely - * output, and before another value is to be output. - * <p> - * Default handling (without pretty-printing) will output a single - * comma to separate the two. Pretty-printer is - * to output a comma as well, but can surround that with other - * (white-space) decoration. - */ - @Override - public void writeObjectEntrySeparator(JsonGenerator jg) throws IOException { - jg.writeRaw(','); - _objectIndenter.writeIndentation(jg, _nesting); - } - - @Override - public void writeEndObject(JsonGenerator jg, int nrOfEntries) throws IOException { - --_nesting; - if (nrOfEntries > 1) { - _objectIndenter.writeIndentation(jg, _nesting); - } else { - jg.writeRaw(' '); - } - jg.writeRaw('}'); - } - - @Override - public void writeStartArray(JsonGenerator jg) throws IOException { - ++_nesting; - jg.writeRaw('['); - } - - @Override - public void beforeArrayValues(JsonGenerator jg) throws IOException { - _arrayIndenter.writeIndentation(jg, _nesting); - } - - /** - * Method called after an array value has been completely - * output, and before another value is to be output. - * <p> - * Default handling (without pretty-printing) will output a single - * comma to separate the two. Pretty-printer is - * to output a comma as well, but can surround that with other - * (white-space) decoration. - */ - @Override - public void writeArrayValueSeparator(JsonGenerator gen) throws IOException { - gen.writeRaw(','); - _arrayIndenter.writeIndentation(gen, _nesting); - } - - @Override - public void writeEndArray(JsonGenerator gen, int nrOfValues) throws IOException { - --_nesting; - - if (_nesting == 0) { - gen.writeRaw('\n'); - } - if (nrOfValues > 1) { - _arrayIndenter.writeIndentation(gen, _nesting); - } else { - gen.writeRaw(' '); - } - gen.writeRaw(']'); - } - - /* - /********************************************************** - /* Helper classes - /********************************************************** - */ - - /** - * Dummy implementation that adds no indentation whatsoever - */ - public static class NopIndenter implements Indenter, java.io.Serializable { - public static final NopIndenter instance = new NopIndenter(); - - @Override - public void writeIndentation(JsonGenerator jg, int level) throws IOException { - } - - @Override - public boolean isInline() { - return true; - } - } - - /** - * This is a very simple indenter that only adds a - * single space for indentation. It is used as the default - * indenter for array values. - */ - public static class FixedSpaceIndenter extends NopIndenter { - @SuppressWarnings("hiding") - public static final FixedSpaceIndenter instance = new FixedSpaceIndenter(); - - @Override - public void writeIndentation(JsonGenerator jg, int level) throws IOException { - jg.writeRaw(' '); - } - - @Override - public boolean isInline() { - return true; - } - } -} diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/json/int01-cleanjson/int01.1.json b/asterixdb/asterix-app/src/test/resources/runtimets/results/json/int01-cleanjson/int01.1.json index 1e25a41..f83d375 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/results/json/int01-cleanjson/int01.1.json +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/json/int01-cleanjson/int01.1.json @@ -1,2 +1 @@ -[ [ 1, 2 ] - ] +[ [ 1, 2 ] ] \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/json/int01-losslessjson/int01.1.json b/asterixdb/asterix-app/src/test/resources/runtimets/results/json/int01-losslessjson/int01.1.json index a0533de..2280279 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/results/json/int01-losslessjson/int01.1.json +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/json/int01-losslessjson/int01.1.json @@ -1,2 +1,7 @@ -[ { "orderedlist": [ { "int64": 1 }, { "int64": 2 } ] } - ] +[ { + "orderedlist" : [ { + "int64" : 1 + }, { + "int64" : 2 + } ] +} ] diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/json/issue-ASTERIXDB-1165/nullablefield.1.json b/asterixdb/asterix-app/src/test/resources/runtimets/results/json/issue-ASTERIXDB-1165/nullablefield.1.json index f2868b6..6f98a7f 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/results/json/issue-ASTERIXDB-1165/nullablefield.1.json +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/json/issue-ASTERIXDB-1165/nullablefield.1.json @@ -1,2 +1 @@ -[ 3 - ] +[ 3 ] diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/non-finite/non-finite.1.json b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/non-finite/non-finite.1.json index 78d4801..d576906 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/non-finite/non-finite.1.json +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/non-finite/non-finite.1.json @@ -1,2 +1,5 @@ -[ { "NaN": "NaN", "Infinity": "INF", "-Infinity": "-INF" } - ] \ No newline at end of file +[ { + "NaN" : "NaN", + "Infinity" : "INF", + "-Infinity" : "-INF" +} ]