How to convert a Java Date object into a JRuby Time object? - jruby

Using JRuby, is there a good way to convert a Java Date object into a JRuby Time object? I'm using the latest version of JRuby (1.3.1) and Java SE 6.

This should work fine:
Time.at(java.util.Date.new.getTime/1000)

Related

JSON path extractor throws error when added to sampler

I am trying to extract a token from response received in json. I have used jpgc-json-2.1 as well as jpgc-json-2.6 json plugin with JMeter. I am using JMeter version 2.13.
When I try to add a post processor to an HTTP sampler, I get this error in message box: cannot find class:com/jayway/jsonpath/PathNotFoundException
I have added jmeter-plugins-cmn-jmeter-0.3.jar to lib and jmeter-plugins-json-2.6.jar and jmeter-plugins-manager-0.11.jar to ext folder.
Any pointers would be appreciated.
Thanks
If you have to use JMeter 2.13 for some reason, you need to get the matching JSON Plugins version, in your case it would be JMeterPlugins-ExtrasLibs-1.4.0.zip which you will need to install manually.
Be aware that JMeter 2.13 is a little bit outdated, it was released in March 2015 so it is 2+ years old for the moment so I would recommend updating to the latest JMeter version (JMeter 3.2 as of now). Newer JMeter versions normally have new features (for instance JSON Extractor), bug fixes and performance improvements.
Since JMeter 3.0, there is a native JSON extractor by default.
I would highly suggest you use JMeter 3.2 and this one.
No need for plugins here.

Alternatives to Newtonsoft.JSON for Monodroid

We currently use Newtonsoft.JSON for notation and serialization/de-serialization of JSON objects in our C# based projects (along the lines of the following), which we also need to share with an application which has been written using Xamarin MonoDroid
[JsonProperty("type")]
public string theType { get; set; }
....
JsonConvert.DeserializeObject<List<OurModel>>(jsonString);
However, the Newtonsoft.JSON isn't compatible with Mono
Presumably, there is an easy solution to handling JSON data BOTH within the C# environment as well as Monodroid? Ideally, so that we can have a common class that is shared between the two projects?
As listed on the Json.NET homepage, "Json.NET supports Windows, Windows Store, Windows Phone, Mono, and Xamarin."
Newtonsoft is the company that makes Json.NET - so the namespace that the library uses is "Newtonsoft.Json". They are both referring to the same library.
I have successfully used Json.NET in my Xamarin.Android applications.
If you aren't sure where to get a copy of the library that will work with your Xamarin.Android application, try using NuGet

Use json.org on SoapUI groovy

I'm trying to use org.json on groovy SoapUI to convert a JSON string into XML.
But When I'm trying to perform my groovy script (this one)
import org.json.JSONObject
import org.json.XML
def str = "{'name':'JSON','integer':1,'double':2.0,'boolean':true,'nested':{'id':42},'array':[1,2,3]}";
JSONObject json = new JSONObject(str);
String xml = XML.toString(json);
log.info(xml)
I'm getting an error "unable to resolve class org.json.JSONObject , line 1, column 1.
I downloaded the jar on http://mvnrepository.com/artifact/org.json/json/20141113 , I put it on SoapUI/bin/ext but It's not working.
Can someone please help me with this?
Coping the json-20141113.jar in SOAPUI_HOME\bin\ext works for me, and your code executes correctly, logging this:
Thu Feb 12 21:58:53 CET 2015:INFO:<boolean>true</boolean><array>1</array><array>2</array><array>3</array><double>2.0</double><name>JSON</name><integer>1</integer><nested><id>42</id></nested>
Note that in order to load the libraries you must restart SOAPUI, maybe this is causing your error.
Note also that the jar you linked is compiled with java 1.8 so check if you run SOAPUI using this version of java if not then you will receive Unsupported major.minor version 52.0 error. I say this because SOAPUI is available to download with or without java; if you download it with java the version is java 1.7. If this is the case you must download java 1.8 and modify SOAPUI_HOME\bin\soapui.bat to use the correct version.
Hope this helps,

How to deserialize JSON in a Windows 8 App seamlessly

The Web API Client Library NuGet Packag brings in JSON.NET and some handy extension methods for deserializing JSON like so:
response.Content.ReadAsAsync<IEnumerable<Product>>().Result
But this package is not compatible with Windows 8 App projects. How can I deserialize my JSON objects in the same generic way without this NuGet package?
What do you mean by saying "not compatible with Win 8"?
The Microsoft.AspNet.WebApi.Client has been developed to support Win8.
Install-Package Microsoft.AspNet.WebApi.Client
Install just this package, not entire Web API.
You can see the release notes here, in the blog post by Henrik Frystyk Nielsen - http://blogs.msdn.com/b/henrikn/archive/2012/08/15/asp-net-web-api-released-and-a-preview-of-what-s-next.aspx
The Microsoft ASP.NET Web API Client Libraries package adds support for formatting
content negotiation to System.Net.Http when writing Windows Store Apps.
It includes support for JSON, XML, form URL encoded data, as well as MIME multipart.
This package requires Visual Studio 2012 and Windows 8.
There are at least 2 JSON serializers available for Windows Store apps:
DataContractJsonSerializer is a part of .NET framework.
Json.NET is supported as well. You can add it into a Windows Store app project if you install just this package: Install-Package Newtonsoft.Json
What exactly are you refering to with "deserialize my JSON objects in the same generic way"?

Parsing and Writing JSON using Ant

Has anyone managed to parse and write JSON in a task in Ant?
I need to parse a json file, modify it and then write it back on disk. I managed to parse it using the rhino engine from JDK 6 but i'm stuck because I don't know how to serialize it back to disk.
It seemes I need a JSON serializer, rhino does not apparently include one.
Recent versions of Rhino should have a JSON object: see this bug that was resolved as fixed in 2010, and the actual class is called NativeJSON and has a stringify method that should let you retrieve a JSON string.
JSON.stringify is available with Rhino 1.7R3 onwards as part of the ECMAScript 5 work.
See: https://developer.mozilla.org/En/New_in_Rhino_1.7R3