Setup ctakes project with JSON output - json

I am trying to setup a ctakes application which gives a JSON output.
I have taken the ctakes module from https://codeload.github.com/apache/ctakes/zip/ctakes-4.0.0
I am trying to convert jcas object to json as below
CAS cas = jcas.getCas();
JsonCasSerializer jcs = new JsonCasSerializer();
jcs.setPrettyPrint(true);
StringWriter sw = new StringWriter();
jcs.serialize(cas, sw);
System.out.println(sw.toString());
But it seems in the downloaded project setup, there is no dependency for JsonCasSerializer. I have googled and found that we need to add uimaj-json jar in my project. I have added the same as external dependency (uimaj-json-3.1.1)- I have tried different versions as well. But I am getting multiple issues after adding the same jar into the project.
My understanding is that while adding the uimaj-json jar, my POM already contains the below dependency and the newly included uimaj-json jar has a lot of dependencies which is not in compatible with my current application uimj-core version.
<dependency>
<groupId>org.apache.uima</groupId>
<artifactId>uimaj-core</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.uima</groupId>
<artifactId>uimafit-core</artifactId>
<version>2.1.0</version>
</dependency>
Kindly help.
Do we have any sample ctakes project which contains jcas to json conversion?

Issue resolved!
It was a version mismatch between uimaj-core and uimaj-json. I was mixing the versions of uimaj-core and uimaj-json. You should use both of same version. I have used 2.8.1 for both.
Please refer:
https://www.mail-archive.com/dev#ctakes.apache.org/msg03498.html

Related

Generated protoc file creates a target source with error

I have tried to make a project that connects to a DB and takes information and outputes them in a desktop application through grpc.
But, when I compile it I get "Error:(20,18) java: cannot find symbol" in a target file( which is auto-generated by protoc.
I can't understand the issue with this. I have tried to change the compiler of mvn, to change the version on protoc, to setup a different JDK, everything just gets worse that it already is.
My project can be viewed here : https://github.com/Diana-Ioana/grpc
My db and error with the generated target files that crashes is : https://imgur.com/a/T6taLXF
I have no idea what to do now. Any help would be greate, thank you!
It looks like the "cannot find symbol" is referring to javax.annotation.Generated. In that case you can add a dependency on annotations-api:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>annotations-api</artifactId>
<version>6.0.53</version>
<!-- Generated has #Retention(SOURCE), so not needed at runtime -->
<scope>provided</scope>
</dependency>
Originally this answer suggested javax.annotation-api, but that library is licensed CDDL so gRPC changed its recommendation.
<!-- The old suggestion. Uses CDDL-licensed library -->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2</version>
</dependency>

error: package com.google.appengine.labs.repackaged.org.json does not exist

I want to return JSON object back to the client side.I add dependencies and it is not working again.What is the purpose of 'repackaged'?I can not find any documentation of this pacakge to add in pom.xml.It allows me to create a JSONObject but in my console appear this error?!
pom.xml
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
<version>${struts.version}</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-labs</artifactId>
<version>${appengine.app.version}</version>
<scope>test</scope>
</dependency>
I used Gson and works for me.It is easy to implement and convert Java object to JSON and vice versa!Here is GSON dependency:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
Treat the 'repackaged' package as internal GAE implementation choices that may change. Such classes have their package path surgically altered to include repackaged so that they won't conflict with your choices.
I've had problems with Eclipse offering repackaged classes up as viable options. How to hide some Eclipse autocomplete results shows a way to fix that.
Just a follow up on this for IntelliJ users. You can tell the IDE to not offer repackaged classes in:
(for IntelliJ 2016.1)
Settings > Editor > General > Auto Import > Exclude from Import and
Completion
Enter there the following and you are done.
com.google.appengine.labs.repackaged
com.google.appengine.repackaged

Rest-assured JsonPath working in JUnit Test but not when deployed in application (Weblogic)

A little background first.
I have an application that is deployed in Weblogic. It receives a Json response from a Service. I'm trying to use JsonPath to navigate the tree and I'm having an unusual issue.
I'm using Maven to build/deploy the application.
Dependency:
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>json-path</artifactId>
<version>1.8.1</version>
</dependency>
After getting it running with the full response in Junit and realizing that it wasn't working in the application when deployed, I made it simpler and hard coded a very small subset of the data.
{
"ChangeStatus": {
"Code": {
"value": "1002"
},
"Description": {
"value": "Matched more then 10 records"
}
}
}
Here's what I'm looking at right now...
String miniJson = "{\"ChangeStatus\":{\"Code\":{\"value\":\"1002\"},\"Description\":{\"value\":\"Matched more then 10 records\"}}}";
JsonPath miniJsonPath = new JsonPath(miniJson);
String statusCode = miniJsonPath.getString("ChangeStatus.Code.value");
In JUnit, this code works and I can assert 1002 successfully.
In the application after pushing to weblogic, this exact code snippet does not work.
It throws a NoSuchMethodError.
Any ideas would be welcome.
FYI, we are on Weblogic 10.3.6
Thanks in advance!
I am not an expert in Weblogic, but as an alternative you can include
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.0-rc1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.2.0-rc1</version>
</dependency>
and create a class ChangeStatus with 2 members Code and Description and then you can deserialize the JSON using:
`new ObjectMapper().readValue(miniJson, ChangeStatus.class)`
Hope it hepls.
What I discovered is that jsonpath depends upon antlr.
Weblogic also includes this package, but I believe it is an older version.
I fixed the problem by telling Weblogic to use the classes included in the app.
weblogic.xml
<wls:container-descriptor>
<wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
</wls:container-descriptor>

org.json.simple.JSONObject VS org.json.JSONObject , JSONException cannot be resolved to a type

First: can someone provide an explanation of the differences between org.json.simple.JSONObject and org.json.JSONObject?
Second: I have a code with org.json.JSONObject and org.json.JSONException. When I edit the code in eclipse ( JUNO) it resolves the type of JSONException and imports the package org.json.JSONException but when I run the project using maven in command line I have a problem ( JSONException cannot be resolved to a type). I tried to solve the issue by adding dependency to pom.xml like this :
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
but I am not sure if it is the right one . I even download the jar of org.
java-json.jar and add it to web deployment assembly but still the same error. Can anyone help ?
org.json and org.json.simple are two different Java libraries, which are incompatible with each other. The fact that they have the same name is only a misleading coincidence.
To compare the two libraries:
General comparison = http://www.rojotek.com/blog/2009/05/07/a-review-of-5-java-json-libraries/
org.json.simple = http://code.google.com/p/json-simple/
org.json = http://json.org/java

Jersey No WebApplication provider is present when jersey-* dependency added

I have a simple Spring & Jersey application, which works perfectly well for consuming requests through a simple Resource. However, I'd like to return a JSON response - containing a simple JSON serialization of an object. To achieve this, I've added a maven dependency for jersey-json. As soon as I add this dependency, however, I get this error at server startup:
com.sun.jersey.api.container.ContainerException: No WebApplication provider is present at
com.sun.jersey.spi.container.WebApplicationFactory.createWebApplication(WebApplicationFactory.java:69) at
com.sun.jersey.spi.container.servlet.ServletContainer.create(ServletContainer.java:391)
I'm not totally clear upon exactly what a provider is, but I'm pretty certain that there should be a default one found.
For completeness, here's my Resource:
#Path("/scan")
#Resource
#Component
public class ScanResource {
#GET
#Produces(MediaType.APPLICATION_JSON)
#Path("/{barcode}")
public List<Scan> getScansForBarcode(#PathParam("barcode") Long barcode){
..snip..
return results;
}
}
A Scan object is a simple Entity Bean object.
The mvn dependency is:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.11</version>
</dependency>
Does anyone know why I might be getting the No WebApplication provider is present Exception? Any thoughts on how I might resolve it?
Thanks
You need to have jersey-server jar on your classpath as well. And you need to make sure that all your jars are from the same version, Jersey runtime won't be able to use provided classes otherwise.
Additionally (most likely not relevant here, but..) there is a recent change in module structure - servlet dependencies were separated to new modules. So if you are using servlets, you might want to depend on jersey-servlet (which depends on jersey-server).
I am also had this issue. The issue was resolved by having same version for "jersey-json" and "jersey-servlet"maven dependencies.
EX:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.13</version>
</dependency>