Swagger exception when trying to resolve protcol buffer generated Java classes - swagger

I am trying to generate a json rest api. My return Object to the client are classes generated from protocol buffers. So I tweacked jackson to convert the protobuf messages into json,so the rest api works. But when adding swagger, I get an exception when trying to create the swagger definition file.
Here is how I try to create the definition file:
SwaggerConfiguration oasConfig = new SwaggerConfiguration().openAPI(oas);
Reader reader = new Reader(oasConfig);
OpenAPI openAPI = reader.read(app.getClasses());
swagger = Json.pretty(openAPI);
The Exception I am getting is
java.lang.IllegalArgumentException: Conflicting setter definitions for property "author": bisq.social.protobuf.PrivateTradeChatMessage$Builder#setAuthor(bisq.social.protobuf.ChatUser) vs bisq.social.protobuf.PrivateTradeChatMessage$Builder#setAuthor(bisq.social.protobuf.ChatUser$Builder)
at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder._selectSetterFromMultiple(POJOPropertyBuilder.java:561)
Since the Java classes being analyzed here are generated, I am not able to change them.
Is there a way to make swagger work with protobuf generated classes?
This is using swagger 2.2.0 and jackson 2.13.2

Related

How can I convert version 1.0 edmx file content in to POJO's?

I want this in hybris project. i have added dependencies and plug in pojogen-maven-plugin for 4.6.0 version. But I get error for Navigation property in EDMX.
Invocation of method 'getNavigationType' in class org.apache.olingo.ext.pojogen.V4Utility threw exception
java.lang.NullPointerException at entityType.vm
Please not none of my entity types in EDMX have navigation property as key .
There could be a couple of things that could go wrong here like.
The Navigation property you have defined might not be correct or there could be a bug in the V4Utility class itself.
What I would recommend is that you debug the code with other projects that do something similar. e.g. OData to OpenAPI converter or OpenAPI.NET.OData Converter. You can try parsing your $metadata EDMX with these tool. If they can its most likely a bug in the V4Utility class itself

How to generate model objects from Json Schema / Json in xcode (swift)?

I have generated Json(s) for each java class using Gson library. Some of them are in hierarchy nature while others are completely independent. I am looking for a way to convert these Json to plain object (getter and setter methods) in swift. Is there any way to do it? For Java we can convert them using JsonSchema2Pojo
try JSON4SWIFT.
I feel,thats the equivalent for jsonschema2pojo in java
Updated :
Try QuickType,It even has a plugin for Xcode

How do I detect a Composite Primary Key in Grails 3.0?

I am currently migrating a Grails 2.4 project to Grails 3.0.10 or 3.1.0.M3.
In Grails 2.4, the following method is a workaround that allows me to detect whether a Domain Class features a composite primary key:
void isCompositePrimaryKey(GrailsDomainClass targetClass) {
def binder = new GrailsDomainBinder()
def idMapping = binder.getMapping(targetClass).identity
return idMapping instanceof org.codehaus.groovy.grails.orm.hibernate.cfg.CompositeIdentity
}
I cannot find a way to detect this in the Public API.
Though GrailsDomainClass still exists in the implementation source code, I cannot seem to access it from my project nor can I find the old CompositeIdentity.
An alternative strategy could be via targetClass.getIdentifier().getType()
but I cannot find any documentation on how to detect a composite key using the identity type.
Solved this simply by adding an additional explicit (non-transitive) dependency to build.gradle for the Hibernate 4 GORM implementation package.
(I determined the package and version by looking in the local gradle files cache but gradle dependencies would also have worked.)
Added to build.gradle:
compile 'org.grails:grails-datastore-gorm-hibernate4:5.0.0.RC2'`
This allows access to the internal API, then the above method still works.
NB. The GORM developers also advise that there is existing GORM API for this, via the PersistentEntity and MappingContext classes without using GrailsDomainClass.

How to use JAXB marshalling with Grails

Can JAXB be used as the marshaller for Grails? My domain classes are JAXB annotated Java classes and GORM is currently marshalling them but not distinguishing between empty and null strings. JAXB can make this distinction, so I would like to use JAXB if possible.
JAXB is being used on the client side and I'm trying to get these Java objects from the server to the client without changing them, but GORM causes null strings to become empty strings.
How can I setup JAXB to replace the Grails marshalling? Any answer should include an example where there are a list of objects of the same type and they get marshalled together in some wrapper element (as this happens on an index action and is common in my application). The name of the tag of the wrapper element is less important. Grails uses "list", which works with JAXB, but other marshallers I've seen use the plural of the object type, which also works with JAXB.
I used the marshalling code in this post (see the blog link for more): Is it possible to programmatically configure JAXB?
Then I modified the marshal helper class to do a little more work and use it in Grails as follows:
def results = MyObj.list()
def xmlString = MarshalHelper.marshal(MyObj.class,results,"myObjs")
render( text: xmlString, contentType: "text/xml" )

Access resource bundle outside struts action class

There are several ways to handle resource bundle using Struts 2.3 framework. This includes using certain UI tags in the View class or getText() method in your Action class.
However, there is no straight-forward mechanism to access this resource bundle in a java class or any other class except View and Action.
I found two ways to access it in a java class,however, they fail to completely replace the old MessageResources of Struts 1.2 framework.
Following are the two ways with drawback of each
Using ResourceBundle class of java.util package.
Locale locale = (Locale)request.getSession().getAttribute(ConstantsFnl.LOCALE_KEY);
ResourceBundle rb = ResourceBundle.getBundle(bundle,locale);
message = rb.getString(key);
The drawback with this approach is you cannot pass an array of arguments which can be replaced in your message text.This functionality was present in Struts 1.2 with MessageReosurces.
Using DefaultTextProvider of Struts 2.3 framework.
DefaultTextProvider dtp = new DefaultTextProvider();
return dtp.getText(key, (String[])params);
Though this approach gives you a way to pass an array of arguments to be replaced in your message text, it does not give you a mechanism to specify the locale or specify the bundle to be searched.Again,this functionality is present in Struts 1.2 with MessageResources class.
Looking for an optimum approach.Any help on this would be great.
You can use methods found in:
com.opensymphony.xwork2.util.LocalizedTextUtil

Resources