天道酬勤,学无止境

json

java.io.IOException Not a data file after converting JSON to Avro with Avro Tools

I have a JSON file and an avro schema file, which correctly describes it's structure. I then convert the JSON file with the Avro tools into an avro file, without getting an error, like this: java -jar .\avro-tools-1.7.7.jar fromjson --schema-file .\data.avsc .\data.json > .\data.avro I then convert the generated Avro file back to JSON to verify that I got a valid Avro file like this: java -jar .\avro-tools-1.7.7.jar tojson .\data.avro > .\data.json This throws the error: Exception in thread "main" java.io.IOException: Not a data file. at org.apache.avro.file.DataFileStream.initialize

2021-07-13 17:36:45    分类:问答    java   json   avro   avro-tools

Why are GET requests returning JSON disallowed by default?

As part of the ASP.NET MVC 2 Beta 2 update, JSON GET requests are disallowed by default. It appears that you need to set the JsonRequestBehavior field to JsonRequestBehavior.AllowGet before returning a JsonResult object from your controller. public JsonResult IsEmailValid(...) { JsonResult result = new JsonResult(); result.Data = ..... ; result.JsonRequestBehavior = JsonRequestBehavior.AllowGet; return result; } What is the reasoning behind this? If I am using JSON GET to try and do some remote validation, should I be using a different technique instead?

2021-07-13 17:35:45    分类:问答    asp.net   asp.net-mvc   json

Use jQuery to attach JSON to a form and submit it

Given this empty form, how would I use jQuery to attach a JSON object as params and then submit it? The form should standard submit, not AJAX. <form action="/comments" method="post" id="comments_form"> <submit>Post</submit> </form>

2021-07-13 17:08:26    分类:问答    jquery   json   forms

Grails send request as JSON and parse it in controller

I want to send a request as JSON and in my controller I want to parse this JSON and get the parameters I want. for example this is the request: {"param1":"val1"} I want to parse this request and get "param1" value. I used request.JSON but still I got null. Is there any other way to solve this? Thanks,

2021-07-13 17:07:53    分类:问答    json   grails   request   grails-2.0

Implicit default values when deserializing JSON using Jackson

When deserializing a variety of JSON messages, I want to provide a default value for attributes of a certain type. It is generally suggested to simply specify the value in the Class, but this is error-prone if you have to do this across many Classes. You might forget one and end up with null instead of a default value. My intention is to set every property that is an Optional<T> to Optional.absent. Since null is exactly what Optional is trying to eliminate, using them with Jackson has proven to be frustrating. Most features of Jackson that allow you to customize the deserialization process

2021-07-13 16:54:35    分类:问答    java   json   jackson   deserialization

Jackson ObjectMapper throwing NullPointerException even with NON_NULL

When the following JSON is used and either "phones" or "emailAddresses" are null, I'm getting a NullPointerException. JSON: { "item": { "messages": { "user.phone.missing": { "type": "warning", "key": "user.phone.missing", "message": "User profile does not have a phone number", "code": null }, "user.email.missing": { "type": "warning", "key": "user.email.missing", "message": "User profile does not have an email address", "code": null }, "user.es.sync.failed": { "type": "error", "key": "user.es.sync.failed", "message": "Unable to sync user", "code": null } }, "user": { "firstName": "Test",

2021-07-13 16:21:45    分类:问答    java   json   nullpointerexception   jackson   objectmapper

JSON value with apostrophe [duplicate]

This question already has answers here: JSON.stringify() not escaping apostrophe (2 answers) Closed 7 years ago. I have an element with a rel attribute that contains a JSON string, something like: rel='{"id":"#id#","name":"#name#"}' Then, in my javascript code, I use $.parseJSON to parse this data. This works correctly - besides for cases where name contains an apostrophe. I've tried using jsStringFormat, a coldfusion replace that replaces all single quotes with escaped single quotes, etc, but I can't seem to hit on a correct solution. I know this is probably simple, but how do I get the code

2021-07-13 15:51:16    分类:问答    jquery   json   coldfusion   apostrophe

Jackson 2.0 compatibility with Jackson 1.x annotations?

I have an older framework class that is annotated with jackson 1.x. My application uses jackson 2.0 to handle json serialization. Is it possible to configure jackson 2.0 to understand the "old" annotations? currently these annotations are simply ignored.

2021-07-13 15:40:10    分类:问答    json   jackson   backwards-compatibility

Combining JSON_SEARCH and JSON_EXTRACT get me: “Invalid JSON path expression.”

I have a table names "campaigns". One of the columns is named "filter_apps" and his type is JSON I have file rows and they just contain array of tokens like so: ["be3beb1fe916ee653ab825fd8fe022", "c130b917983c719495042e31306ffb"] ["4fef3f1999c78cf987960492da4d2a"] ["106c274e319bdeae8bcf8daf515b1f"] ["2521f0df6cffb7487d527319674cf3"] ["c130b917983c719495042e31306ffb"] Examples: SELECT JSON_SEARCH(filter_apps, 'one', 'c130b917983c719495042e31306ffb') FROM campaigns; Result: "$[1]" null null null "$[0]" Right now everything is correct, the matched columns come back. If I make a test I can prove

2021-07-13 15:38:07    分类:问答    mysql   json   mysql-5.7

Jackson @JsonRawValue for Map's value

I have the following Java bean class with gets converted to JSON using Jackson. public class Thing { public String name; @JsonRawValue public Map content = new HashMap(); } content is a map who's values will be raw JSON from another source. For example: String jsonFromElsewhere = "{ \"foo\": \"bar\" }"; Thing t = new Thing(); t.name = "test"; t.content.put("1", jsonFromElsewhere); The desired generated JSON is: {"name":"test","content":{"1":{ "foo": "bar" }}} However using @JsonRawValue results in: {"name":"test","content":{1={ "foo": "bar" }}} What I need is a way to specify @JsonRawValue for

2021-07-13 15:08:23    分类:问答    java   json   jackson