How to use @JsonIdentityInfo with circular references?

I am trying to use the @JsonIdentityInfo from Jackson 2 as described here. For testing purposes I created the following two classes: public class A { private B b; // constructor(s) and getter/setter omitted } public class B { private A a; // see above } Of course, the naive approach failes: @Test public void … Read more

Parse JSON response with Swift 3

I have JSON looking like this: {“posts”: [ { “id”:”1″,”title”:”title 1″ }, { “id”:”2″,”title”:”title 2″ }, { “id”:”3″,”title”:”title 3″ }, { “id”:”4″,”title”:”title 4″ }, { “id”:”5″,”title”:”title 5″ } ], “text”:”Some text”, “result”:1 } How can I parse that JSON with Swift 3? I have this: let url = URL(string: “http://domain.com/file.php”)! let request = URLRequest(url: url) … Read more

ReferenceError: “Sheets” is not defined

This is my first attempt with script editor. I was assigned to do a script to crate pivot table for google sheet. //creating pivot table through script editor for google sheet function addPivotTable() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheetName = “Sheet1”; // Create a new sheet which will contain our Pivot Table var pivotTableSheet … Read more

spring mvc rest response json and xml

I have the requirement to return the result from the database either as a string in xml-structure or as json-structure. I’ve got a solution, but I don’t know, if this one is the best way to solve this. I have two methods here: @RequestMapping(value = “/content/json/{ids}”, method = RequestMethod.GET) public ResponseEntity<String> getContentByIdsAsJSON(@PathVariable(“ids”) String ids) { … Read more

Is it possible to query for datetime ranges with the Stripe API?

Using the Stripe API, I’d like to be able to query for date ranges or, failing that, dates that are greater than or less than some arbitrary date. I know that I can query for something based on an exact date, e.g.,: https://api.stripe.com/v1/events?created=1336503409 But I want something along the lines of… # Search for events … Read more

Fastest way to import millions of JSON documents to MongoDB

I have more than 10 million JSON documents of the form : [“key”: “val2”, “key1” : “val”, “{\”key\”:\”val”, \”key2\”:\”val2″}”] in one file. Importing using JAVA Driver API took around 3 hours, while using the following function (importing one BSON at a time): public static void importJSONFileToDBUsingJavaDriver(String pathToFile, DB db, String collectionName) { // open file … Read more

How can I put a Postgres JSON value into a Rails fixture?

I just added a Postgres json type to a Rails/Active Record table I’m working with. I’d like to populate a record with a default value in Rails fixtures: fixture_id: existing_column: “foobar” newly_added_column: <%= JSON.dump({:reason => ‘foobar’}) %> Previously, I’d stored stringified JSON this way in a text column. However, when I now run this unit … Read more

Switch off UTF escaping in JsonBuilder

I’m trying to use JsonBuilder in groovy servlet (extending HttpServlet) Here is a snippet: public void doGet(HttpServletRequest request, HttpServletResponse response) { response.setContentType(‘text/plain’) response.setCharacterEncoding(‘utf-8’) def pw = response.getWriter() pw.println(new JsonBuilder([‘city’: ‘Москва’])) pw.println([сity: ‘Москва’]) } The output is {“city”:”\u041C\u043E\u0441\u043A\u0432\u0430″} {сity=Москва} I just don’t know nothing about UTF escaping in JsonBuilder, googling also did not give my anything … Read more

Get last element of a JSON object in JavaScript

I got a json object in JavaScript like: var json = {“20121207″:”13”, “20121211”:”9″, “20121213”:”7″, “20121219”:”4″}; without knowing the name of the last key. (The keys are in ascending order) How can I read the value (and key) of the last element? Answer var highest = json[ Object.keys(json).sort().pop() ]; Object.keys (ES5, shimmable) returns an array of … Read more