You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "smiklosovic (via GitHub)" <gi...@apache.org> on 2023/04/27 10:26:29 UTC
[GitHub] [cassandra] smiklosovic opened a new pull request, #2297: CASSANDRA-16855
smiklosovic opened a new pull request, #2297:
URL: https://github.com/apache/cassandra/pull/2297
Thanks for sending a pull request! Here are some tips if you're new here:
* Ensure you have added or run the [appropriate tests](https://cassandra.apache.org/_/development/testing.html) for your PR.
* Be sure to keep the PR description updated to reflect all changes.
* Write your PR title to summarize what this PR proposes.
* If possible, provide a concise example to reproduce the issue for a faster review.
* Read our [contributor guidelines](https://cassandra.apache.org/_/development/index.html)
* If you're making a documentation change, see our [guide to documentation contribution](https://cassandra.apache.org/_/development/documentation.html)
Commit messages should follow the following format:
```
<One sentence description, usually Jira title or CHANGES.txt summary>
<Optional lengthier description (context on patch)>
patch by <Authors>; reviewed by <Reviewers> for CASSANDRA-#####
Co-authored-by: Name1 <email1>
Co-authored-by: Name2 <email2>
```
The [Cassandra Jira](https://issues.apache.org/jira/projects/CASSANDRA/issues/)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2297: CASSANDRA-16855
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2297:
URL: https://github.com/apache/cassandra/pull/2297#discussion_r1180758496
##########
src/java/org/apache/cassandra/utils/JsonUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.cassandra.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.util.BufferRecyclers;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import org.apache.cassandra.io.util.File;
+import org.apache.cassandra.io.util.FileInputStreamPlus;
+import org.apache.cassandra.io.util.FileOutputStreamPlus;
+import org.apache.cassandra.serializers.MarshalException;
+
+import static org.apache.cassandra.io.util.File.WriteMode.OVERWRITE;
+
+public final class JsonUtils
+{
+ public static final ObjectMapper JSON_OBJECT_MAPPER = new ObjectMapper(new JsonFactory());
+
+ public static final ObjectWriter JSON_OBJECT_WRITER;
+
+ static
+ {
+ JSON_OBJECT_MAPPER.registerModule(new JavaTimeModule());
+ JSON_OBJECT_MAPPER.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+ JSON_OBJECT_WRITER = JSON_OBJECT_MAPPER.writerWithDefaultPrettyPrinter();
Review Comment:
change the name of this variable to `JSON_OBJECT_PRETTY_WRITER` to indicate that this write is writing pretilly
##########
src/java/org/apache/cassandra/utils/JsonUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.cassandra.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.util.BufferRecyclers;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import org.apache.cassandra.io.util.File;
+import org.apache.cassandra.io.util.FileInputStreamPlus;
+import org.apache.cassandra.io.util.FileOutputStreamPlus;
+import org.apache.cassandra.serializers.MarshalException;
+
+import static org.apache.cassandra.io.util.File.WriteMode.OVERWRITE;
+
+public final class JsonUtils
+{
+ public static final ObjectMapper JSON_OBJECT_MAPPER = new ObjectMapper(new JsonFactory());
+
+ public static final ObjectWriter JSON_OBJECT_WRITER;
+
+ static
+ {
+ JSON_OBJECT_MAPPER.registerModule(new JavaTimeModule());
+ JSON_OBJECT_MAPPER.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+ JSON_OBJECT_WRITER = JSON_OBJECT_MAPPER.writerWithDefaultPrettyPrinter();
Review Comment:
change the name of this variable to `JSON_OBJECT_PRETTY_WRITER` to indicate that this writer is writing pretilly
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2297: CASSANDRA-16855
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2297:
URL: https://github.com/apache/cassandra/pull/2297#discussion_r1180756022
##########
src/java/org/apache/cassandra/utils/JsonUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.cassandra.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.util.BufferRecyclers;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import org.apache.cassandra.io.util.File;
+import org.apache.cassandra.io.util.FileInputStreamPlus;
+import org.apache.cassandra.io.util.FileOutputStreamPlus;
+import org.apache.cassandra.serializers.MarshalException;
+
+import static org.apache.cassandra.io.util.File.WriteMode.OVERWRITE;
+
+public final class JsonUtils
+{
+ public static final ObjectMapper JSON_OBJECT_MAPPER = new ObjectMapper(new JsonFactory());
+
+ public static final ObjectWriter JSON_OBJECT_WRITER;
+
+ static
+ {
+ JSON_OBJECT_MAPPER.registerModule(new JavaTimeModule());
+ JSON_OBJECT_MAPPER.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+ JSON_OBJECT_WRITER = JSON_OBJECT_MAPPER.writerWithDefaultPrettyPrinter();
+ }
+
+ private JsonUtils()
+ {
+ }
+
+ /**
+ * Quotes string contents using standard JSON quoting.
+ */
+ public static String quoteAsJsonString(String s)
+ {
+ // In future should update to directly use `JsonStringEncoder.getInstance()` but for now:
+ return new String(BufferRecyclers.getJsonStringEncoder().quoteAsString(s));
+ }
+
+ public static Object decodeJson(byte[] json)
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.readValue(json, Object.class);
+ }
+ catch (IOException exc)
+ {
+ throw new MarshalException("Error decoding JSON bytes: " + exc.getMessage());
+ }
+ }
+
+ public static Object decodeJson(String json)
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.readValue(json, Object.class);
+ }
+ catch (IOException exc)
+ {
+ throw new MarshalException("Error decoding JSON string: " + exc.getMessage());
+ }
+ }
+
+ public static byte[] writeAsJsonBytes(Object value) throws MarshalException
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.writeValueAsBytes(value);
+ }
+ catch (IOException exc)
+ {
+ throw new MarshalException("Error writing as JSON: " + exc.getMessage());
+ }
+ }
+
+ public static String writeAsJsonString(Object value) throws MarshalException
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.writeValueAsString(value);
+ }
+ catch (IOException exc)
+ {
+ throw new MarshalException("Error writing as JSON: " + exc.getMessage());
+ }
+ }
+
+ public static String writeAsPrettyJsonString(Object value) throws MarshalException
+ {
+ try
+ {
+ return JSON_OBJECT_WRITER.writeValueAsString(value);
+ }
+ catch (IOException exc)
+ {
+ throw new MarshalException("Error writing as JSON: " + exc.getMessage());
+ }
+ }
+
+ public static Map<String, String> fromJsonMap(String json)
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.readValue(json, Map.class);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static List<String> fromJsonList(String json)
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.readValue(json, List.class);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * @deprecated Use org.apache.cassandra.cql3.Json#writeAsJsonString() instead
+ */
+ @Deprecated
+ public static String json(Object object)
Review Comment:
this might just go away
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2297: CASSANDRA-16855
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2297:
URL: https://github.com/apache/cassandra/pull/2297#discussion_r1180718613
##########
test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java:
##########
@@ -44,6 +44,10 @@
import org.apache.cassandra.SchemaLoader;
import org.apache.cassandra.UpdateBuilder;
import org.apache.cassandra.Util;
+
Review Comment:
changes in this class happen to be not related to this ticket at all, revert these changes on commit
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] smiklosovic closed pull request #2297: CASSANDRA-16855
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic closed pull request #2297: CASSANDRA-16855
URL: https://github.com/apache/cassandra/pull/2297
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2297: CASSANDRA-16855
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2297:
URL: https://github.com/apache/cassandra/pull/2297#discussion_r1180754742
##########
src/java/org/apache/cassandra/hints/HintsDescriptor.java:
##########
@@ -78,8 +78,9 @@
Pattern.compile("^[a-fA-F0-9]{8}\\-[a-fA-F0-9]{4}\\-[a-fA-F0-9]{4}\\-[a-fA-F0-9]{4}\\-[a-fA-F0-9]{12}\\-(\\d+)\\-(\\d+)\\.hints$");
private static final ObjectReader jsonMapReader;
- static {
- jsonMapReader = Json.JSON_OBJECT_MAPPER.readerFor(Map.class);
+ static
+ {
+ jsonMapReader = JsonUtils.JSON_OBJECT_MAPPER.readerFor(Map.class);
Review Comment:
this is probably not necessary and may be replaced with `JsonUtils.fromJsonMap`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2297: CASSANDRA-16855
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2297:
URL: https://github.com/apache/cassandra/pull/2297#discussion_r1180757080
##########
src/java/org/apache/cassandra/utils/JsonUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.cassandra.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.util.BufferRecyclers;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import org.apache.cassandra.io.util.File;
+import org.apache.cassandra.io.util.FileInputStreamPlus;
+import org.apache.cassandra.io.util.FileOutputStreamPlus;
+import org.apache.cassandra.serializers.MarshalException;
+
+import static org.apache.cassandra.io.util.File.WriteMode.OVERWRITE;
+
+public final class JsonUtils
+{
+ public static final ObjectMapper JSON_OBJECT_MAPPER = new ObjectMapper(new JsonFactory());
+
+ public static final ObjectWriter JSON_OBJECT_WRITER;
+
+ static
+ {
+ JSON_OBJECT_MAPPER.registerModule(new JavaTimeModule());
+ JSON_OBJECT_MAPPER.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+ JSON_OBJECT_WRITER = JSON_OBJECT_MAPPER.writerWithDefaultPrettyPrinter();
+ }
+
+ private JsonUtils()
+ {
+ }
+
+ /**
+ * Quotes string contents using standard JSON quoting.
+ */
+ public static String quoteAsJsonString(String s)
+ {
+ // In future should update to directly use `JsonStringEncoder.getInstance()` but for now:
+ return new String(BufferRecyclers.getJsonStringEncoder().quoteAsString(s));
+ }
+
+ public static Object decodeJson(byte[] json)
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.readValue(json, Object.class);
+ }
+ catch (IOException exc)
+ {
+ throw new MarshalException("Error decoding JSON bytes: " + exc.getMessage());
+ }
+ }
+
+ public static Object decodeJson(String json)
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.readValue(json, Object.class);
+ }
+ catch (IOException exc)
+ {
+ throw new MarshalException("Error decoding JSON string: " + exc.getMessage());
+ }
+ }
+
+ public static byte[] writeAsJsonBytes(Object value) throws MarshalException
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.writeValueAsBytes(value);
+ }
+ catch (IOException exc)
+ {
+ throw new MarshalException("Error writing as JSON: " + exc.getMessage());
+ }
+ }
+
+ public static String writeAsJsonString(Object value) throws MarshalException
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.writeValueAsString(value);
+ }
+ catch (IOException exc)
+ {
+ throw new MarshalException("Error writing as JSON: " + exc.getMessage());
+ }
+ }
+
+ public static String writeAsPrettyJsonString(Object value) throws MarshalException
+ {
+ try
+ {
+ return JSON_OBJECT_WRITER.writeValueAsString(value);
+ }
+ catch (IOException exc)
+ {
+ throw new MarshalException("Error writing as JSON: " + exc.getMessage());
+ }
+ }
+
+ public static Map<String, String> fromJsonMap(String json)
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.readValue(json, Map.class);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
Review Comment:
this should be MarshalException as rest of the methods throws it
##########
src/java/org/apache/cassandra/utils/JsonUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.cassandra.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.util.BufferRecyclers;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import org.apache.cassandra.io.util.File;
+import org.apache.cassandra.io.util.FileInputStreamPlus;
+import org.apache.cassandra.io.util.FileOutputStreamPlus;
+import org.apache.cassandra.serializers.MarshalException;
+
+import static org.apache.cassandra.io.util.File.WriteMode.OVERWRITE;
+
+public final class JsonUtils
+{
+ public static final ObjectMapper JSON_OBJECT_MAPPER = new ObjectMapper(new JsonFactory());
+
+ public static final ObjectWriter JSON_OBJECT_WRITER;
+
+ static
+ {
+ JSON_OBJECT_MAPPER.registerModule(new JavaTimeModule());
+ JSON_OBJECT_MAPPER.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+ JSON_OBJECT_WRITER = JSON_OBJECT_MAPPER.writerWithDefaultPrettyPrinter();
+ }
+
+ private JsonUtils()
+ {
+ }
+
+ /**
+ * Quotes string contents using standard JSON quoting.
+ */
+ public static String quoteAsJsonString(String s)
+ {
+ // In future should update to directly use `JsonStringEncoder.getInstance()` but for now:
+ return new String(BufferRecyclers.getJsonStringEncoder().quoteAsString(s));
+ }
+
+ public static Object decodeJson(byte[] json)
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.readValue(json, Object.class);
+ }
+ catch (IOException exc)
+ {
+ throw new MarshalException("Error decoding JSON bytes: " + exc.getMessage());
+ }
+ }
+
+ public static Object decodeJson(String json)
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.readValue(json, Object.class);
+ }
+ catch (IOException exc)
+ {
+ throw new MarshalException("Error decoding JSON string: " + exc.getMessage());
+ }
+ }
+
+ public static byte[] writeAsJsonBytes(Object value) throws MarshalException
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.writeValueAsBytes(value);
+ }
+ catch (IOException exc)
+ {
+ throw new MarshalException("Error writing as JSON: " + exc.getMessage());
+ }
+ }
+
+ public static String writeAsJsonString(Object value) throws MarshalException
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.writeValueAsString(value);
+ }
+ catch (IOException exc)
+ {
+ throw new MarshalException("Error writing as JSON: " + exc.getMessage());
+ }
+ }
+
+ public static String writeAsPrettyJsonString(Object value) throws MarshalException
+ {
+ try
+ {
+ return JSON_OBJECT_WRITER.writeValueAsString(value);
+ }
+ catch (IOException exc)
+ {
+ throw new MarshalException("Error writing as JSON: " + exc.getMessage());
+ }
+ }
+
+ public static Map<String, String> fromJsonMap(String json)
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.readValue(json, Map.class);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static List<String> fromJsonList(String json)
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.readValue(json, List.class);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
Review Comment:
change to marshal
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2297: CASSANDRA-16855
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2297:
URL: https://github.com/apache/cassandra/pull/2297#discussion_r1180760235
##########
src/java/org/apache/cassandra/utils/JsonUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.cassandra.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.util.BufferRecyclers;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import org.apache.cassandra.io.util.File;
+import org.apache.cassandra.io.util.FileInputStreamPlus;
+import org.apache.cassandra.io.util.FileOutputStreamPlus;
+import org.apache.cassandra.serializers.MarshalException;
+
+import static org.apache.cassandra.io.util.File.WriteMode.OVERWRITE;
+
+public final class JsonUtils
+{
+ public static final ObjectMapper JSON_OBJECT_MAPPER = new ObjectMapper(new JsonFactory());
+
+ public static final ObjectWriter JSON_OBJECT_WRITER;
+
+ static
+ {
+ JSON_OBJECT_MAPPER.registerModule(new JavaTimeModule());
+ JSON_OBJECT_MAPPER.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+ JSON_OBJECT_WRITER = JSON_OBJECT_MAPPER.writerWithDefaultPrettyPrinter();
+ }
+
+ private JsonUtils()
+ {
+ }
+
+ /**
+ * Quotes string contents using standard JSON quoting.
+ */
+ public static String quoteAsJsonString(String s)
+ {
+ // In future should update to directly use `JsonStringEncoder.getInstance()` but for now:
+ return new String(BufferRecyclers.getJsonStringEncoder().quoteAsString(s));
+ }
+
+ public static Object decodeJson(byte[] json)
+ {
+ try
+ {
+ return JSON_OBJECT_MAPPER.readValue(json, Object.class);
+ }
+ catch (IOException exc)
Review Comment:
change all occurences of `exc` and `e` to `ex`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2297: CASSANDRA-16855
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2297:
URL: https://github.com/apache/cassandra/pull/2297#discussion_r1180758496
##########
src/java/org/apache/cassandra/utils/JsonUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.cassandra.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.util.BufferRecyclers;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import org.apache.cassandra.io.util.File;
+import org.apache.cassandra.io.util.FileInputStreamPlus;
+import org.apache.cassandra.io.util.FileOutputStreamPlus;
+import org.apache.cassandra.serializers.MarshalException;
+
+import static org.apache.cassandra.io.util.File.WriteMode.OVERWRITE;
+
+public final class JsonUtils
+{
+ public static final ObjectMapper JSON_OBJECT_MAPPER = new ObjectMapper(new JsonFactory());
+
+ public static final ObjectWriter JSON_OBJECT_WRITER;
+
+ static
+ {
+ JSON_OBJECT_MAPPER.registerModule(new JavaTimeModule());
+ JSON_OBJECT_MAPPER.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+ JSON_OBJECT_WRITER = JSON_OBJECT_MAPPER.writerWithDefaultPrettyPrinter();
Review Comment:
change name to `JSON_OBJECT_PRETTY_WRITER` to indicate that this write is writing pretilly
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org