http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/SingleLinePrettyPrinter.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/SingleLinePrettyPrinter.java b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/SingleLinePrettyPrinter.java new file mode 100644 index 0000000..52f68a0 --- /dev/null +++ b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/SingleLinePrettyPrinter.java @@ -0,0 +1,404 @@ +/* + * 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.aql; + +import java.io.*; + +import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.core.io.SerializedString; +import com.fasterxml.jackson.core.util.DefaultIndenter; +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; + } + } +}
http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java index bfe0e33..07a7cc5 100644 --- a/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java +++ b/asterixdb/asterix-common/src/test/java/org/apache/asterix/test/aql/TestExecutor.java @@ -31,18 +31,20 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.Inet4Address; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.Arrays; +import java.util.ArrayList; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.*; import org.apache.asterix.common.config.GlobalConfig; import org.apache.asterix.common.utils.ServletUtil.Servlets; import org.apache.asterix.test.base.ComparisonException; @@ -67,9 +69,7 @@ import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.StandardHttpRequestRetryHandler; import org.apache.http.util.EntityUtils; import org.apache.hyracks.util.StorageUtil; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.node.ObjectNode; public class TestExecutor { @@ -398,9 +398,10 @@ public class TestExecutor { try { // First try to parse the response for a JSON error response. - JSONObject result = new JSONObject(errorBody); - String[] errors = { result.getJSONArray("error-code").getString(0), result.getString("summary"), - result.getString("stacktrace") }; + ObjectMapper om = new ObjectMapper(); + JsonNode result = om.readTree(errorBody); + String[] errors = { result.get("error-code").asText(), result.get("summary").asText(), + result.get("stacktrace").asText() }; GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, errors[2]); exceptionMsg = "HTTP operation failed: " + errors[0] + "\nSTATUS LINE: " + httpResponse.getStatusLine() + "\nSUMMARY: " + errors[1] + "\nSTACKTRACE: " + errors[2]; @@ -540,15 +541,16 @@ public class TestExecutor { throw new NullPointerException("Statement parameter required."); } RequestBuilder builder = RequestBuilder.post(endpoint); - JSONObject content = new JSONObject(); + ObjectMapper om = new ObjectMapper(); + ObjectNode content = om.createObjectNode(); + for (CompilationUnit.Parameter param : injectStatement(statement, stmtParam, otherParams)) { + content.put(param.getName(), param.getValue()); + } try { - for (CompilationUnit.Parameter param : injectStatement(statement, stmtParam, otherParams)) { - content.put(param.getName(), param.getValue()); - } - } catch (JSONException e) { - throw new IllegalArgumentException("Request object construction failed.", e); + builder.setEntity(new StringEntity(om.writeValueAsString(content), ContentType.APPLICATION_JSON)); + } catch (JsonProcessingException e) { + e.printStackTrace(); } - builder.setEntity(new StringEntity(content.toString(), ContentType.APPLICATION_JSON)); builder.setCharset(StandardCharsets.UTF_8); return builder.build(); } @@ -1024,11 +1026,11 @@ public class TestExecutor { StringWriter actual = new StringWriter(); IOUtils.copy(executeJSONGet, actual, StandardCharsets.UTF_8); String config = actual.toString(); - String nodePid = StringUtils.substringBetween(config, "\"pid\": ", ",").trim(); - if (nodePid == null) { - throw new IllegalArgumentException("Coud not find process for node id: " + nodeId); + int nodePid = new ObjectMapper().readValue(config, ObjectNode.class).get("pid").asInt(); + if (nodePid <= 1) { + throw new IllegalArgumentException("Could not retrieve node pid from admin API"); } - ProcessBuilder pb = new ProcessBuilder("kill", "-9", nodePid); + ProcessBuilder pb = new ProcessBuilder("kill", "-9", Integer.toString(nodePid)); pb.start().waitFor(); } @@ -1122,15 +1124,22 @@ public class TestExecutor { ArrayList<String> toBeDropped = new ArrayList<>(); InputStream resultStream = executeQueryService("select dv.DataverseName from Metadata.`Dataverse` as dv;", getEndpoint(Servlets.QUERY_SERVICE)); - resultStream = ResultExtractor.extract(resultStream); - StringWriter sw = new StringWriter(); - IOUtils.copy(resultStream, sw, StandardCharsets.UTF_8.name()); - JSONArray result = new JSONArray(sw.toString()); - for (int i = 0; i < result.length(); ++i) { - JSONObject json = result.getJSONObject(i); - String dvName = json.getString("DataverseName"); - if (!dvName.equals("Metadata") && !dvName.equals("Default")) { - toBeDropped.add(dvName); + String out = IOUtils.toString(resultStream); + ObjectMapper om = new ObjectMapper(); + om.setConfig(om.getDeserializationConfig().with(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)); + JsonNode result; + try { + result = om.readValue(out, ObjectNode.class).get("results"); + } catch (JsonMappingException e) { + result = om.createArrayNode(); + } + for (int i = 0; i < result.size(); i++) { + JsonNode json = result.get(i); + if (json != null) { + String dvName = json.get("DataverseName").asText(); + if (!dvName.equals("Metadata") && !dvName.equals("Default")) { + toBeDropped.add(dvName); + } } } if (!toBeDropped.isEmpty()) { @@ -1151,4 +1160,5 @@ public class TestExecutor { throw th; } } + } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/feed/message/EndFeedMessage.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/feed/message/EndFeedMessage.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/feed/message/EndFeedMessage.java index 06aafdd..7a3a376 100644 --- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/feed/message/EndFeedMessage.java +++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/feed/message/EndFeedMessage.java @@ -18,12 +18,13 @@ */ package org.apache.asterix.external.feed.message; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.asterix.active.EntityId; import org.apache.asterix.external.feed.management.FeedConnectionId; import org.apache.asterix.external.util.FeedConstants; import org.apache.asterix.external.util.FeedUtils.FeedRuntimeType; -import org.json.JSONException; -import org.json.JSONObject; + +import com.fasterxml.jackson.databind.node.ObjectNode; /** * @deprecated A feed control message indicating the need to end the feed. This message is dispatched @@ -82,8 +83,9 @@ public class EndFeedMessage extends FeedMessage { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject obj = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode obj = om.createObjectNode(); obj.put(FeedConstants.MessageConstants.MESSAGE_TYPE, messageType.name()); obj.put(FeedConstants.MessageConstants.DATAVERSE, connectionId.getFeedId().getDataverse()); obj.put(FeedConstants.MessageConstants.FEED, connectionId.getFeedId().getEntityName()); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/TweetParser.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/TweetParser.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/TweetParser.java index d23d490..95a5cd1 100644 --- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/TweetParser.java +++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/TweetParser.java @@ -18,20 +18,20 @@ */ package org.apache.asterix.external.parser; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.asterix.builders.AbvsBuilderFactory; import org.apache.asterix.builders.IARecordBuilder; import org.apache.asterix.builders.IAsterixListBuilder; import org.apache.asterix.builders.ListBuilderFactory; -import org.apache.asterix.builders.OrderedListBuilder; import org.apache.asterix.builders.RecordBuilderFactory; +import org.apache.asterix.builders.UnorderedListBuilder; import org.apache.asterix.external.api.IRawRecord; import org.apache.asterix.external.api.IRecordDataParser; import org.apache.asterix.om.base.AMutablePoint; import org.apache.asterix.om.base.ANull; -import org.apache.asterix.om.types.AOrderedListType; import org.apache.asterix.om.types.ARecordType; import org.apache.asterix.om.types.ATypeTag; -import org.apache.asterix.om.types.AUnionType; import org.apache.asterix.om.types.BuiltinType; import org.apache.asterix.om.types.IAType; import org.apache.asterix.om.util.container.IObjectPool; @@ -40,12 +40,10 @@ import org.apache.hyracks.api.exceptions.HyracksDataException; import org.apache.hyracks.data.std.api.IMutableValueStorage; import org.apache.hyracks.data.std.util.ArrayBackedValueStorage; import org.apache.hyracks.util.string.UTF8StringWriter; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; import java.io.DataOutput; import java.io.IOException; +import java.util.Iterator; public class TweetParser extends AbstractDataParser implements IRecordDataParser<String> { private final IObjectPool<IARecordBuilder, ATypeTag> recordBuilderPool = new ListObjectPool<>( @@ -62,121 +60,85 @@ public class TweetParser extends AbstractDataParser implements IRecordDataParser aPoint = new AMutablePoint(0, 0); } - private void parseJSONArray(JSONArray jArray, DataOutput output, AOrderedListType orderedListType) - throws IOException, JSONException { + private void parseUnorderedList(JsonNode jArray, DataOutput output) throws IOException { ArrayBackedValueStorage itemBuffer = getTempBuffer(); - OrderedListBuilder orderedList = (OrderedListBuilder) getOrderedListBuilder(); + UnorderedListBuilder unorderedListBuilder = (UnorderedListBuilder) getUnorderedListBuilder(); - orderedList.reset(orderedListType); - for (int iter1 = 0; iter1 < jArray.length(); iter1++) { + unorderedListBuilder.reset(null); + for (int iter1 = 0; iter1 < jArray.size(); iter1++) { itemBuffer.reset(); - if (writeField(jArray.get(iter1), orderedListType == null ? null : orderedListType.getItemType(), - itemBuffer.getDataOutput())) { - orderedList.addItem(itemBuffer); + if (writeField(jArray.get(iter1), null, itemBuffer.getDataOutput())) { + unorderedListBuilder.addItem(itemBuffer); } } - orderedList.write(output, true); + unorderedListBuilder.write(output, true); } - private boolean writeFieldWithFieldType(Object fieldObj, IAType fieldType, DataOutput out) - throws HyracksDataException { + private boolean writeField(JsonNode fieldObj, IAType fieldType, DataOutput out) throws IOException { boolean writeResult = true; - IAType chkFieldType; - chkFieldType = fieldType instanceof AUnionType ? ((AUnionType) fieldType).getActualType() : fieldType; - try { - switch (chkFieldType.getTypeTag()) { + if (fieldType != null) { + switch (fieldType.getTypeTag()) { case STRING: - out.write(fieldType.getTypeTag().serialize()); - utf8Writer.writeUTF8(fieldObj.toString(), out); + out.write(BuiltinType.ASTRING.getTypeTag().serialize()); + utf8Writer.writeUTF8(fieldObj.asText(), out); break; case INT64: - out.write(fieldType.getTypeTag().serialize()); - if (fieldObj instanceof Integer) { - out.writeLong(((Integer) fieldObj).longValue()); - } else { - out.writeLong((Long) fieldObj); - } + aInt64.setValue(fieldObj.asLong()); int64Serde.serialize(aInt64, out); break; case INT32: - out.write(fieldType.getTypeTag().serialize()); - out.writeInt((Integer) fieldObj); + out.write(BuiltinType.AINT32.getTypeTag().serialize()); + out.writeInt(fieldObj.asInt()); break; case DOUBLE: - out.write(fieldType.getTypeTag().serialize()); - out.writeDouble((Double) fieldObj); + out.write(BuiltinType.ADOUBLE.getTypeTag().serialize()); + out.writeDouble(fieldObj.asDouble()); break; case BOOLEAN: - out.write(fieldType.getTypeTag().serialize()); - out.writeBoolean((Boolean) fieldObj); + out.write(BuiltinType.ABOOLEAN.getTypeTag().serialize()); + out.writeBoolean(fieldObj.asBoolean()); break; case RECORD: - if (((JSONObject) fieldObj).length() != 0) { - writeResult = writeRecord((JSONObject) fieldObj, out, (ARecordType) chkFieldType); - } else { - writeResult = false; - } - break; - case ORDEREDLIST: - if (((JSONArray) fieldObj).length() != 0) { - parseJSONArray((JSONArray) fieldObj, out, (AOrderedListType) chkFieldType); - } else { - writeResult = false; - } + writeRecord(fieldObj, out, (ARecordType) fieldType); break; default: writeResult = false; } - } catch (IOException | JSONException e) { - throw new HyracksDataException(e); - } - return writeResult; - } - - private boolean writeFieldWithoutFieldType(Object fieldObj, DataOutput out) throws HyracksDataException { - boolean writeResult = true; - try { - if (fieldObj == JSONObject.NULL) { + } else { + if (fieldObj.isNull()) { nullSerde.serialize(ANull.NULL, out); - } else if (fieldObj instanceof Integer) { + } else if (fieldObj.isInt()) { out.write(BuiltinType.AINT32.getTypeTag().serialize()); - out.writeInt((Integer) fieldObj); - } else if (fieldObj instanceof Boolean) { + out.writeInt(fieldObj.asInt()); + } else if (fieldObj.isBoolean()) { out.write(BuiltinType.ABOOLEAN.getTypeTag().serialize()); - out.writeBoolean((Boolean) fieldObj); - } else if (fieldObj instanceof Double) { + out.writeBoolean(fieldObj.asBoolean()); + } else if (fieldObj.isDouble()) { out.write(BuiltinType.ADOUBLE.getTypeTag().serialize()); - out.writeDouble((Double) fieldObj); - } else if (fieldObj instanceof Long) { + out.writeDouble(fieldObj.asDouble()); + } else if (fieldObj.isLong()) { out.write(BuiltinType.AINT64.getTypeTag().serialize()); - out.writeLong((Long) fieldObj); - } else if (fieldObj instanceof String) { + out.writeLong(fieldObj.asLong()); + } else if (fieldObj.isTextual()) { out.write(BuiltinType.ASTRING.getTypeTag().serialize()); - utf8Writer.writeUTF8((String) fieldObj, out); - } else if (fieldObj instanceof JSONArray) { - if (((JSONArray) fieldObj).length() != 0) { - parseJSONArray((JSONArray) fieldObj, out, null); + utf8Writer.writeUTF8(fieldObj.asText(), out); + } else if (fieldObj.isArray()) { + if ((fieldObj).size() != 0) { + parseUnorderedList(fieldObj, out); } else { writeResult = false; } - } else if (fieldObj instanceof JSONObject) { - if (((JSONObject) fieldObj).length() != 0) { - writeResult = writeRecord((JSONObject) fieldObj, out, null); + } else if (fieldObj.isObject()) { + if ((fieldObj).size() != 0) { + writeRecord(fieldObj, out, null); } else { writeResult = false; } } - } catch (IOException | JSONException e) { - throw new HyracksDataException(e); } return writeResult; } - private boolean writeField(Object fieldObj, IAType fieldType, DataOutput out) throws HyracksDataException { - return fieldType == null ? writeFieldWithoutFieldType(fieldObj, out) - : writeFieldWithFieldType(fieldObj, fieldType, out); - } - private int checkAttrNameIdx(String[] nameList, String name) { int idx = 0; if (nameList != null) { @@ -190,13 +152,11 @@ public class TweetParser extends AbstractDataParser implements IRecordDataParser return -1; } - public boolean writeRecord(JSONObject obj, DataOutput out, ARecordType curRecType) - throws IOException, JSONException { + public void writeRecord(JsonNode obj, DataOutput out, ARecordType curRecType) throws IOException { IAType[] curTypes = null; String[] curFNames = null; int fieldN; int attrIdx; - boolean writeRecord = false; ArrayBackedValueStorage fieldValueBuffer = getTempBuffer(); ArrayBackedValueStorage fieldNameBuffer = getTempBuffer(); @@ -216,9 +176,8 @@ public class TweetParser extends AbstractDataParser implements IRecordDataParser for (int iter1 = 0; iter1 < fieldN; iter1++) { fieldValueBuffer.reset(); DataOutput fieldOutput = fieldValueBuffer.getDataOutput(); - if (obj.isNull(curFNames[iter1])) { - if (curRecType.getFieldType(curFNames[iter1]) != null - && !(curRecType.getFieldType(curFNames[iter1]) instanceof AUnionType)) { + if (obj.get(curFNames[iter1]).isNull()) { + if (curRecType.isClosedField(curFNames[iter1])) { throw new HyracksDataException("Closed field " + curFNames[iter1] + " has null value."); } else { continue; @@ -226,15 +185,18 @@ public class TweetParser extends AbstractDataParser implements IRecordDataParser } else { if (writeField(obj.get(curFNames[iter1]), curTypes[iter1], fieldOutput)) { recBuilder.addField(iter1, fieldValueBuffer); - writeRecord = true; } } } } else { //open record type + int closedFieldCount = 0; IAType curFieldType = null; - for (String attrName : JSONObject.getNames(obj)) { - if (obj.isNull(attrName) || obj.length() == 0) { + String attrName; + Iterator<String> iter = obj.fieldNames(); + while (iter.hasNext()) { + attrName = iter.next(); + if (obj.get(attrName).isNull() || obj.size() == 0) { continue; } attrIdx = checkAttrNameIdx(curFNames, attrName); @@ -245,29 +207,29 @@ public class TweetParser extends AbstractDataParser implements IRecordDataParser fieldNameBuffer.reset(); DataOutput fieldOutput = fieldValueBuffer.getDataOutput(); if (writeField(obj.get(attrName), curFieldType, fieldOutput)) { - writeRecord = true; if (attrIdx == -1) { aString.setValue(attrName); stringSerde.serialize(aString, fieldNameBuffer.getDataOutput()); recBuilder.addField(fieldNameBuffer, fieldValueBuffer); } else { recBuilder.addField(attrIdx, fieldValueBuffer); + closedFieldCount++; } } } + if (curRecType != null && closedFieldCount < curFNames.length) { + throw new HyracksDataException("Non-null field is null"); + } } - if (writeRecord) { - recBuilder.write(out, true); - } - return writeRecord; + recBuilder.write(out, true); } private IARecordBuilder getRecordBuilder() { return recordBuilderPool.allocate(ATypeTag.RECORD); } - private IAsterixListBuilder getOrderedListBuilder() { - return listBuilderPool.allocate(ATypeTag.ORDEREDLIST); + private IAsterixListBuilder getUnorderedListBuilder() { + return listBuilderPool.allocate(ATypeTag.UNORDEREDLIST); } private ArrayBackedValueStorage getTempBuffer() { @@ -279,9 +241,9 @@ public class TweetParser extends AbstractDataParser implements IRecordDataParser try { //TODO get rid of this temporary json resetPools(); - JSONObject jsObj = new JSONObject(record.get()); - writeRecord(jsObj, out, recordType); - } catch (JSONException | IOException e) { + ObjectMapper om = new ObjectMapper(); + writeRecord(om.readTree(record.get()), out, recordType); + } catch (IOException e) { throw new HyracksDataException(e); } } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.10.adm ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.10.adm b/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.10.adm index b155305..579caac 100644 --- a/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.10.adm +++ b/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.10.adm @@ -1,10 +1,34 @@ { - "metadata_node": "asterix_nc1", - "partitions": { - "0": "ID:0, Original Node: asterix_nc1, IODevice: 0, Active Node: asterix_nc1", - "1": "ID:1, Original Node: asterix_nc1, IODevice: 1, Active Node: asterix_nc1", - "2": "ID:2, Original Node: asterix_nc2, IODevice: 0, Active Node: asterix_nc2", - "3": "ID:3, Original Node: asterix_nc2, IODevice: 1, Active Node: asterix_nc2" + "metadata_node" : "asterix_nc1", + "partitions" : { + "0" : { + "partitionId" : 0, + "nodeId" : "asterix_nc1", + "activeNodeId" : "asterix_nc1", + "active" : true, + "iodeviceNum" : 0 }, - "state": "ACTIVE" + "1" : { + "partitionId" : 1, + "nodeId" : "asterix_nc1", + "activeNodeId" : "asterix_nc1", + "active" : true, + "iodeviceNum" : 1 + }, + "2" : { + "partitionId" : 2, + "nodeId" : "asterix_nc2", + "activeNodeId" : "asterix_nc2", + "active" : true, + "iodeviceNum" : 0 + }, + "3" : { + "partitionId" : 3, + "nodeId" : "asterix_nc2", + "activeNodeId" : "asterix_nc2", + "active" : true, + "iodeviceNum" : 1 + } + }, + "state" : "ACTIVE" } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.5.adm ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.5.adm b/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.5.adm index 6b31475..5f58ff7 100644 --- a/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.5.adm +++ b/asterixdb/asterix-installer/src/test/resources/integrationts/replication/results/failback/node_failback/node_failback.cluster_state.5.adm @@ -1,10 +1,34 @@ { - "metadata_node": "asterix_nc2", - "partitions": { - "0": "ID:0, Original Node: asterix_nc1, IODevice: 0, Active Node: asterix_nc2", - "1": "ID:1, Original Node: asterix_nc1, IODevice: 1, Active Node: asterix_nc2", - "2": "ID:2, Original Node: asterix_nc2, IODevice: 0, Active Node: asterix_nc2", - "3": "ID:3, Original Node: asterix_nc2, IODevice: 1, Active Node: asterix_nc2" + "metadata_node" : "asterix_nc2", + "partitions" : { + "0" : { + "partitionId" : 0, + "nodeId" : "asterix_nc1", + "activeNodeId" : "asterix_nc2", + "active" : true, + "iodeviceNum" : 0 }, - "state": "ACTIVE" + "1" : { + "partitionId" : 1, + "nodeId" : "asterix_nc1", + "activeNodeId" : "asterix_nc2", + "active" : true, + "iodeviceNum" : 1 + }, + "2" : { + "partitionId" : 2, + "nodeId" : "asterix_nc2", + "activeNodeId" : "asterix_nc2", + "active" : true, + "iodeviceNum" : 0 + }, + "3" : { + "partitionId" : 3, + "nodeId" : "asterix_nc2", + "activeNodeId" : "asterix_nc2", + "active" : true, + "iodeviceNum" : 1 + } + }, + "state" : "ACTIVE" } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/pom.xml ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/pom.xml b/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/pom.xml index dccbcb1..2fa86b4 100644 --- a/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/pom.xml +++ b/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/pom.xml @@ -48,9 +48,12 @@ <version>2.2.1</version> </dependency> <dependency> - <groupId>org.json</groupId> - <artifactId>json</artifactId> - <type>jar</type> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-core</artifactId> </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordManagerGeneratorMojo.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordManagerGeneratorMojo.java b/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordManagerGeneratorMojo.java index d7479bc..909edc3 100644 --- a/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordManagerGeneratorMojo.java +++ b/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordManagerGeneratorMojo.java @@ -33,7 +33,6 @@ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.project.MavenProject; -import org.json.JSONException; /** * @goal generate-record-manager @@ -95,8 +94,6 @@ public class RecordManagerGeneratorMojo extends AbstractMojo { type.addToMap(typeMap); } catch (FileNotFoundException fnfe) { throw new MojoExecutionException("could not find type description file " + inputFiles[i], fnfe); - } catch (JSONException jse) { - throw new MojoExecutionException("could not parse type description file " + inputFiles[i], jse); } catch (IOException e) { throw new MojoExecutionException("error closing type description file " + inputFiles[i], e); } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordType.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordType.java b/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordType.java index 6702a8f..d322371 100644 --- a/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordType.java +++ b/asterixdb/asterix-maven-plugins/record-manager-generator-maven-plugin/src/main/java/org/apache/asterix/recordmanagergenerator/RecordType.java @@ -19,26 +19,41 @@ package org.apache.asterix.recordmanagergenerator; +import java.io.IOException; import java.io.Reader; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Map; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.json.JSONTokener; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; public class RecordType { enum Type { - BYTE (1, "byte", "get", "put", "(byte)0xde", "TypeUtil.Byte.append", "TypeUtil.Byte.appendFixed"), - SHORT (2, "short", "getShort", "putShort", "(short)0xdead", "TypeUtil.Short.append", "TypeUtil.Short.appendFixed"), - INT (4, "int", "getInt", "putInt", "0xdeadbeef", "TypeUtil.Int.append", "TypeUtil.Int.appendFixed"), - GLOBAL(8, "long", "getLong", "putLong", "0xdeadbeefdeadbeefl", "TypeUtil.Global.append", "TypeUtil.Global.appendFixed"); - - Type(int size, String javaType, String bbGetter, String bbSetter, String deadMemInitializer, String appender, String tabAppender) { + BYTE(1, "byte", "get", "put", "(byte)0xde", "TypeUtil.Byte.append", "TypeUtil.Byte.appendFixed"), + SHORT( + 2, + "short", + "getShort", + "putShort", + "(short)0xdead", + "TypeUtil.Short.append", + "TypeUtil.Short.appendFixed"), + INT(4, "int", "getInt", "putInt", "0xdeadbeef", "TypeUtil.Int.append", "TypeUtil.Int.appendFixed"), + GLOBAL( + 8, + "long", + "getLong", + "putLong", + "0xdeadbeefdeadbeefl", + "TypeUtil.Global.append", + "TypeUtil.Global.appendFixed"); + + Type(int size, String javaType, String bbGetter, String bbSetter, String deadMemInitializer, String appender, + String tabAppender) { this.size = size; this.javaType = javaType; this.bbGetter = bbGetter; @@ -73,10 +88,10 @@ public class RecordType { this.accessible = accessible; } - public static Field fromJSON(JSONObject obj) throws JSONException { - String name = obj.getString("name"); - Type type = parseType(obj.getString("type")); - String initial = obj.optString("initial", null); + public static Field fromJSON(JsonNode obj) { + String name = obj.get("name").asText(); + Type type = parseType(obj.get("type").asText()); + String initial = obj.get("initial") == null ? null : obj.get("initial").asText(); return new Field(name, type, initial, -1, true); } @@ -96,7 +111,7 @@ public class RecordType { String methodName(String prefix) { String words[] = name.split(" "); - assert(words.length > 0); + assert words.length > 0; StringBuilder sb = new StringBuilder(prefix); for (int j = 0; j < words.length; ++j) { String word = words[j]; @@ -108,11 +123,8 @@ public class RecordType { StringBuilder appendMemoryManagerGetMethod(StringBuilder sb, String indent, int level) { sb = indent(sb, indent, level); - sb.append("public ") - .append(type.javaType) - .append(' ') - .append(methodName("get")) - .append("(int slotNum) {\n"); + sb.append("public ").append(type.javaType).append(' ').append(methodName("get")) + .append("(int slotNum) {\n"); sb = indent(sb, indent, level + 1); sb.append("final Buffer buf = buffers.get(slotNum / NO_SLOTS);\n"); sb = indent(sb, indent, level + 1); @@ -120,11 +132,8 @@ public class RecordType { sb = indent(sb, indent, level + 1); sb.append("final ByteBuffer b = buf.bb;\n"); sb = indent(sb, indent, level + 1); - sb.append("return b.") - .append(type.bbGetter) - .append("((slotNum % NO_SLOTS) * ITEM_SIZE + ") - .append(offsetName()) - .append(");\n"); + sb.append("return b.").append(type.bbGetter).append("((slotNum % NO_SLOTS) * ITEM_SIZE + ") + .append(offsetName()).append(");\n"); sb = indent(sb, indent, level); sb.append("}\n"); return sb; @@ -132,19 +141,13 @@ public class RecordType { StringBuilder appendMemoryManagerSetMethod(StringBuilder sb, String indent, int level) { sb = indent(sb, indent, level); - sb.append("public void ") - .append(methodName("set")) - .append("(int slotNum, ") - .append(type.javaType) - .append(" value) {\n"); + sb.append("public void ").append(methodName("set")).append("(int slotNum, ").append(type.javaType) + .append(" value) {\n"); sb = indent(sb, indent, level + 1); sb.append("final ByteBuffer b = buffers.get(slotNum / NO_SLOTS).bb;\n"); sb = indent(sb, indent, level + 1); - sb.append("b.") - .append(type.bbSetter) - .append("((slotNum % NO_SLOTS) * ITEM_SIZE + ") - .append(offsetName()) - .append(", value);\n"); + sb.append("b.").append(type.bbSetter).append("((slotNum % NO_SLOTS) * ITEM_SIZE + ").append(offsetName()) + .append(", value);\n"); sb = indent(sb, indent, level); sb.append("}\n"); return sb; @@ -152,23 +155,18 @@ public class RecordType { StringBuilder appendArenaManagerGetMethod(StringBuilder sb, String indent, int level) { sb = indent(sb, indent, level); - sb.append("public ") - .append(type.javaType) - .append(' ') - .append(methodName("get")) - .append("(long slotNum) {\n"); + sb.append("public ").append(type.javaType).append(' ').append(methodName("get")) + .append("(long slotNum) {\n"); if (initial != null) { - sb = indent(sb, indent, level + 1); - sb.append("if (TRACK_ALLOC_ID) checkAllocId(slotNum);\n"); + sb = indent(sb, indent, level + 1); + sb.append("if (TRACK_ALLOC_ID) checkAllocId(slotNum);\n"); } sb = indent(sb, indent, level + 1); sb.append("final int arenaId = TypeUtil.Global.arenaId(slotNum);\n"); sb = indent(sb, indent, level + 1); sb.append("final int localId = TypeUtil.Global.localId(slotNum);\n"); sb = indent(sb, indent, level + 1); - sb.append("return get(arenaId).") - .append(methodName("get")) - .append("(localId);\n"); + sb.append("return get(arenaId).").append(methodName("get")).append("(localId);\n"); sb = indent(sb, indent, level); sb.append("}\n"); return sb; @@ -176,23 +174,18 @@ public class RecordType { StringBuilder appendArenaManagerSetMethod(StringBuilder sb, String indent, int level) { sb = indent(sb, indent, level); - sb.append("public void ") - .append(methodName("set")) - .append("(long slotNum, ") - .append(type.javaType) - .append(" value) {\n"); + sb.append("public void ").append(methodName("set")).append("(long slotNum, ").append(type.javaType) + .append(" value) {\n"); if (initial != null) { - sb = indent(sb, indent, level + 1); - sb.append("if (TRACK_ALLOC_ID) checkAllocId(slotNum);\n"); + sb = indent(sb, indent, level + 1); + sb.append("if (TRACK_ALLOC_ID) checkAllocId(slotNum);\n"); } sb = indent(sb, indent, level + 1); sb.append("final int arenaId = TypeUtil.Global.arenaId(slotNum);\n"); sb = indent(sb, indent, level + 1); sb.append("final int localId = TypeUtil.Global.localId(slotNum);\n"); sb = indent(sb, indent, level + 1); - sb.append("get(arenaId).") - .append(methodName("set")) - .append("(localId, value);\n"); + sb.append("get(arenaId).").append(methodName("set")).append("(localId, value);\n"); sb = indent(sb, indent, level); sb.append("}\n"); return sb; @@ -200,11 +193,7 @@ public class RecordType { StringBuilder appendInitializers(StringBuilder sb, String indent, int level) { sb = indent(sb, indent, level); - sb.append("bb.") - .append(type.bbSetter) - .append("(slotNum * ITEM_SIZE + ") - .append(offsetName()) - .append(", "); + sb.append("bb.").append(type.bbSetter).append("(slotNum * ITEM_SIZE + ").append(offsetName()).append(", "); if (initial != null) { sb.append(initial); } else { @@ -219,17 +208,11 @@ public class RecordType { return sb; } sb = indent(sb, indent, level); - sb.append("if (bb.") - .append(type.bbGetter) - .append("(itemOffset + ") - .append(offsetName()) - .append(") == ") - .append(type.deadMemInitializer) - .append(") {\n"); + sb.append("if (bb.").append(type.bbGetter).append("(itemOffset + ").append(offsetName()).append(") == ") + .append(type.deadMemInitializer).append(") {\n"); sb = indent(sb, indent, level + 1); - sb.append("String msg = \"invalid value in field ") - .append(offsetName()) - .append(" of slot \" + TypeUtil.Global.toString(slotNum);\n"); + sb.append("String msg = \"invalid value in field ").append(offsetName()) + .append(" of slot \" + TypeUtil.Global.toString(slotNum);\n"); sb = indent(sb, indent, level + 1); sb.append("throw new IllegalStateException(msg);\n"); sb = indent(sb, indent, level); @@ -239,7 +222,7 @@ public class RecordType { String offsetName() { String words[] = name.split(" "); - assert(words.length > 0); + assert (words.length > 0); StringBuilder sb = new StringBuilder(words[0].toUpperCase()); for (int j = 1; j < words.length; ++j) { sb.append("_").append(words[j].toUpperCase()); @@ -271,18 +254,17 @@ public class RecordType { addField("next free slot", Type.INT, "-1", false); } - public static RecordType read(Reader reader) throws JSONException { - JSONTokener tok = new JSONTokener(reader); - JSONObject obj = new JSONObject(tok); - return fromJSON(obj); + public static RecordType read(Reader reader) throws IOException { + ObjectNode node = new ObjectMapper().readValue(reader, ObjectNode.class); + return fromJSON(node); } - public static RecordType fromJSON(JSONObject obj) throws JSONException { - RecordType result = new RecordType(obj.getString("name")); - JSONArray fields = obj.getJSONArray("fields"); - for (int i = 0; i < fields.length(); ++i) { - JSONObject field = fields.getJSONObject(i); - result.fields.add(Field.fromJSON(field)); + public static RecordType fromJSON(ObjectNode obj) { + RecordType result = new RecordType(obj.get("name").asText()); + JsonNode fields = obj.get("fields"); + for (int i = 0; i < fields.size(); i++) { + JsonNode n = fields.get(i); + result.fields.add(Field.fromJSON(n)); } return result; } @@ -298,7 +280,7 @@ public class RecordType { } private void addField(String name, Type type, String initial, boolean accessible) { - if (! modifiable) { + if (!modifiable) { throw new IllegalStateException("cannot modify type anmore"); } fields.add(new Field(name, type, initial, -1, accessible)); @@ -319,7 +301,9 @@ public class RecordType { field.offset = totalSize; final int size = field.type.size; totalSize += size; - if (size > alignment) alignment = size; + if (size > alignment) { + alignment = size; + } } if (totalSize % alignment != 0) { totalSize = ((totalSize / alignment) + 1) * alignment; @@ -340,17 +324,12 @@ public class RecordType { StringBuilder appendConstants(StringBuilder sb, String indent, int level) { sb = indent(sb, indent, level); - sb.append("public static int ITEM_SIZE = ") - .append(totalSize) - .append(";\n"); + sb.append("public static int ITEM_SIZE = ").append(totalSize).append(";\n"); for (int i = 0; i < fields.size(); ++i) { final Field field = fields.get(i); sb = indent(sb, indent, level); - sb.append("public static int ") - .append(field.offsetName()) - .append(" = ") - .append(field.offset).append("; // size: ") - .append(field.type.size).append("\n"); + sb.append("public static int ").append(field.offsetName()).append(" = ").append(field.offset) + .append("; // size: ").append(field.type.size).append("\n"); } return sb; } @@ -366,22 +345,14 @@ public class RecordType { for (int i = 0; i < fields.size(); ++i) { final Field field = fields.get(i); sb = indent(sb, indent, level); - sb.append("sb.append(\"") - .append(padRight(field.name, maxNameWidth)) - .append(" | \");\n"); + sb.append("sb.append(\"").append(padRight(field.name, maxNameWidth)).append(" | \");\n"); sb = indent(sb, indent, level); sb.append("for (int i = 0; i < NO_SLOTS; ++i) {\n"); sb = indent(sb, indent, level + 1); - sb.append(field.type.javaType) - .append(" value = bb.") - .append(field.type.bbGetter) - .append("(i * ITEM_SIZE + ") - .append(field.offsetName()) - .append(");\n"); + sb.append(field.type.javaType).append(" value = bb.").append(field.type.bbGetter) + .append("(i * ITEM_SIZE + ").append(field.offsetName()).append(");\n"); sb = indent(sb, indent, level + 1); - sb.append("sb = ") - .append(field.type.tabAppender) - .append("(sb, value);\n"); + sb.append("sb = ").append(field.type.tabAppender).append("(sb, value);\n"); sb = indent(sb, indent, level + 1); sb.append("sb.append(\" | \");\n"); sb = indent(sb, indent, level); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABinary.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABinary.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABinary.java index b3ee50e..db87ce0 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABinary.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABinary.java @@ -18,13 +18,13 @@ */ package org.apache.asterix.om.base; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.types.BuiltinType; import org.apache.asterix.om.types.IAType; import org.apache.asterix.om.visitors.IOMVisitor; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; public class ABinary implements IAObject { @@ -115,15 +115,16 @@ public class ABinary implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); int start = getStart(); - JSONArray byteArray = new JSONArray(); + ArrayNode byteArray = om.createArrayNode(); for (int i = 0; i < getLength(); i++) { - byteArray.put(bytes[start + i]); + byteArray.add(bytes[start + i]); } - json.put("ABinary", byteArray); + json.set("ABinary", byteArray); return json; } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABitArray.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABitArray.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABitArray.java index 503c920..a15dbad 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABitArray.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABitArray.java @@ -18,9 +18,9 @@ */ package org.apache.asterix.om.base; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.types.BuiltinType; @@ -139,14 +139,15 @@ public final class ABitArray implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); - JSONArray bitArray = new JSONArray(); + ArrayNode bitArray = om.createArrayNode(); for (int i = 0; i < intArray.length; i++) { - bitArray.put(intArray[i]); + bitArray.add(intArray[i]); } - json.put("ABitArray", bitArray); + json.set("ABitArray", bitArray); return json; } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABoolean.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABoolean.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABoolean.java index 2a56cff..a1011d8 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABoolean.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ABoolean.java @@ -18,12 +18,12 @@ */ package org.apache.asterix.om.base; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.types.BuiltinType; import org.apache.asterix.om.types.IAType; import org.apache.asterix.om.visitors.IOMVisitor; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.node.ObjectNode; public final class ABoolean implements IAObject { @@ -80,7 +80,7 @@ public final class ABoolean implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { - return new JSONObject().put("ABoolean", bVal); + public ObjectNode toJSON() { + return new ObjectMapper().createObjectNode().put("ABoolean", bVal); } } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ACircle.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ACircle.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ACircle.java index a99bcda..4878d7a 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ACircle.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ACircle.java @@ -18,8 +18,8 @@ */ package org.apache.asterix.om.base; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.types.BuiltinType; @@ -82,13 +82,14 @@ public class ACircle implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); - JSONObject circle = new JSONObject(); - circle.put("center", center); + ObjectNode circle = om.createObjectNode(); + circle.set("center", center.toJSON()); circle.put("radius", radius); - json.put("ACircle", circle); + json.set("ACircle", circle); return json; } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADate.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADate.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADate.java index 789ad31..9373f90 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADate.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADate.java @@ -20,8 +20,8 @@ package org.apache.asterix.om.base; import java.io.IOException; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.base.temporal.GregorianCalendarSystem; @@ -96,8 +96,9 @@ public class ADate implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); json.put("ADate", chrononTimeInDay); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADateTime.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADateTime.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADateTime.java index f3592e3..75f653e 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADateTime.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADateTime.java @@ -20,13 +20,13 @@ package org.apache.asterix.om.base; import java.io.IOException; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.base.temporal.GregorianCalendarSystem; import org.apache.asterix.om.types.BuiltinType; import org.apache.asterix.om.types.IAType; import org.apache.asterix.om.visitors.IOMVisitor; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.node.ObjectNode; /** * ADateTime type represents the timestamp values. @@ -136,8 +136,9 @@ public class ADateTime implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); json.put("ADateTime", chrononTime); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADayTimeDuration.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADayTimeDuration.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADayTimeDuration.java index cb298b7..d31b8c8 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADayTimeDuration.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADayTimeDuration.java @@ -18,8 +18,9 @@ */ package org.apache.asterix.om.base; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; + +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.types.BuiltinType; @@ -42,12 +43,13 @@ public class ADayTimeDuration implements IAObject { * @see org.apache.hyracks.api.dataflow.value.JSONSerializable#toJSON() */ @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); - JSONObject duration = new JSONObject(); + ObjectNode duration = om.createObjectNode(); duration.put("milliseconds", chrononInMillisecond); - json.put("ADuration", duration); + json.set("ADuration", duration); return json; } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADouble.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADouble.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADouble.java index 4746773..7a2fe06 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADouble.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADouble.java @@ -18,8 +18,9 @@ */ package org.apache.asterix.om.base; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; + +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.types.BuiltinType; @@ -78,8 +79,9 @@ public class ADouble implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); json.put("ADouble", value); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADuration.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADuration.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADuration.java index 27b551b..a3f23d3 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADuration.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ADuration.java @@ -18,8 +18,9 @@ */ package org.apache.asterix.om.base; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; + +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.base.temporal.GregorianCalendarSystem; @@ -117,13 +118,14 @@ public class ADuration implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); - JSONObject duration = new JSONObject(); + ObjectNode duration = om.createObjectNode(); duration.put("months", chrononInMonth); duration.put("milliseconds", chrononInMillisecond); - json.put("ADuration", duration); + json.set("ADuration", duration); return json; } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AFloat.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AFloat.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AFloat.java index 50d1825..f29e659 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AFloat.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AFloat.java @@ -18,8 +18,9 @@ */ package org.apache.asterix.om.base; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; + +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.types.BuiltinType; @@ -78,8 +79,9 @@ public class AFloat implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); json.put("AFloat", value); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt16.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt16.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt16.java index 11dd486..934ef0a 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt16.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt16.java @@ -18,8 +18,9 @@ */ package org.apache.asterix.om.base; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; + +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.types.BuiltinType; @@ -68,8 +69,10 @@ public class AInt16 implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); json.put("AInt16", value); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt32.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt32.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt32.java index 5bbcf77..38a87d7 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt32.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt32.java @@ -18,8 +18,9 @@ */ package org.apache.asterix.om.base; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; + +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.types.BuiltinType; @@ -93,8 +94,9 @@ public class AInt32 implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); json.put("AInt32", value); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt64.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt64.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt64.java index 9047833..02bc8b0 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt64.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt64.java @@ -18,8 +18,9 @@ */ package org.apache.asterix.om.base; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; + +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.types.BuiltinType; @@ -67,8 +68,9 @@ public class AInt64 implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); json.put("AInt64", value); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt8.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt8.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt8.java index 8360d99..5623d37 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt8.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInt8.java @@ -18,8 +18,9 @@ */ package org.apache.asterix.om.base; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; + +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.types.BuiltinType; @@ -67,8 +68,9 @@ public class AInt8 implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); json.put("AInt8", value); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInterval.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInterval.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInterval.java index 5fa99a9..9dfaf3b 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInterval.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AInterval.java @@ -20,8 +20,7 @@ package org.apache.asterix.om.base; import java.io.IOException; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.base.temporal.GregorianCalendarSystem; @@ -156,7 +155,7 @@ public class AInterval implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { + public ObjectNode toJSON() { // TODO(madhusudancs): Remove this method when a printer based JSON serializer is implemented. return null; } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ALine.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ALine.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ALine.java index 4908fa8..9134a3c 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ALine.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ALine.java @@ -18,8 +18,8 @@ */ package org.apache.asterix.om.base; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.types.BuiltinType; @@ -75,13 +75,14 @@ public class ALine implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); - JSONObject line = new JSONObject(); - line.put("p1", p1); - line.put("p2", p2); - json.put("ALine", line); + ObjectNode line = om.createObjectNode(); + line.set("p1", p1.toJSON()); + line.set("p2", p2.toJSON()); + json.set("ALine", line); return json; } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AMissing.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AMissing.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AMissing.java index 6c357e6..2455311 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AMissing.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AMissing.java @@ -18,12 +18,12 @@ */ package org.apache.asterix.om.base; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.types.BuiltinType; import org.apache.asterix.om.types.IAType; import org.apache.asterix.om.visitors.IOMVisitor; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.node.ObjectNode; // This class represents a MISSING object. public class AMissing implements IAObject { @@ -59,8 +59,9 @@ public class AMissing implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); json.put("AMissing", "missing"); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ANull.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ANull.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ANull.java index 859ebb3..ebf7975 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ANull.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/ANull.java @@ -19,12 +19,12 @@ package org.apache.asterix.om.base; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.types.BuiltinType; import org.apache.asterix.om.types.IAType; import org.apache.asterix.om.visitors.IOMVisitor; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.node.ObjectNode; public class ANull implements IAObject { @@ -59,8 +59,9 @@ public class ANull implements IAObject { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); json.put("ANull", "null"); return json; } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d49bc6eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AOrderedList.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AOrderedList.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AOrderedList.java index 7e67e0a..8138a51 100644 --- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AOrderedList.java +++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/base/AOrderedList.java @@ -21,14 +21,14 @@ package org.apache.asterix.om.base; import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.om.types.AOrderedListType; import org.apache.asterix.om.types.BuiltinType; import org.apache.asterix.om.types.IAType; import org.apache.asterix.om.visitors.IOMVisitor; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; public class AOrderedList implements IACollection { @@ -126,14 +126,15 @@ public class AOrderedList implements IACollection { } @Override - public JSONObject toJSON() throws JSONException { - JSONObject json = new JSONObject(); + public ObjectNode toJSON() { + ObjectMapper om = new ObjectMapper(); + ObjectNode json = om.createObjectNode(); - JSONArray list = new JSONArray(); + ArrayNode list = om.createArrayNode(); for (IAObject v : values) { - list.put(v.toJSON()); + list.add(v.toJSON()); } - json.put("AOrderedList", list); + json.set("AOrderedList", list); return json; }