I try to marshall a List<List<String>> to CSV with a route like:
from("direct:ListToCsv").marshal(csvDataFormat_list).convertBodyTo(String.class).to("mock:ListToCsv");
In CsvMarshaller.getRecordValues, there's a "convert to Map" called there that doesn't have the same behavior if camel Spring boot is used (maybe just in camel spring, don't know).
If SpringTypeConverter is enabled (wich is automatic in spring boot) the method "convertTo" throw an ConverterNotFoundException and the route stop there.
Before spring-boot (or if I remove it), the conversion to map in the CsvMarshaller return null and the conversion is executed as list and it works.
So, question... I think it's a bug or do I miss something with the use of Spring for fallback type converter (I didn't use it before)?
Thanks!
[UPDATE]
It seems to be fixed in the next version of camel-csv (2.16.X)
Related
I've been using arrow-kt and spring together a lot lately. I've actually constructed a bridge between the two with several key features, one of which is a spring controller that returns an Either will automatically unwrap it and either handle the exception (Left) or return the result (Right). My long term goal is to publish this as a library.
My latest obstacle is Swagger, or more accurately springdoc openapi. Obviously it is seeing the Either, but i want it to show only the Right value as the success response type. While I know there are annotations where I can set the response model on each controller method individually, I'm trying to avoid this.
My real goal is to setup some global converter so that wherever Swagger sees an Either it will automatically unpack this. I'm just not super familiar with the customization API in Spring doc, and everything I Google just points me to the ApiResponse annotation solution.
How can I define default handling for this type of response?
I have a simple Spring boot project that uses controller mappings to get hard coded information from a class in my project.
For example, if I run the request : localhost:8080/topics, A JSON response is returned with the list of Topic Objects that i have previously created
I want to take this one step further and have a class who's variables are populated by calling this API and parsing the response : https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=demo
I believe this can be done in Java by creating a HTTP connection and reading the data from an input stream, but is the an easier way of doing this with spring boot? Im not fully sure of the name of this procedure hence Im having trouble finding solutions online
Since you are using Spring Boot, making use of Spring's RestTemplate makes sense. It comes with several message converters out of the box, and uses Jackson by default for json content.
Spring has published a good Getting Started page for consuming RESTful web services.
However, the json content returned by that services doesn't look like it will map well to a Java object, so you may have to deserialize it to a HashMap to get to the data you want.
I did an attempt to create something like this.
https://github.com/StanislavLapitsky/SpringSOAProxy
The idea is to register controller interfaces. Each of the interfaces are mapped to some URL. For the interfaces a dynamic proxy are generated (if the implementations are not available locally). So developer just call controller's interface method. The method is invoked for dynamically generated proxy. The proxy uses RestTemplate to call remote URL. It sends and receive JSON and deserializes the returned JSOn to POJO objects returned from the controller.
You need to declare contract - controller interfaces plus DTO to exchange data as well as mapping to understand which URL should be called for each controller.
I have a large object which can be updated in a few steps. I'am facing a partial binding problem. My service consumes json and I can not use #InitBinder along with #RequestBody. Cutting this object to a few small ones is not good a solution, because there is a lot of cross-field validations between steps.
Do you have any ideas how to solve this? I'am looking for a clean solution like: registering a specific object mapper for given #RequestMapping or something like that. Thanks for help.
You should be able to use a PATCH HTTP method
Its the preferred method that you would use when you need partial updates, like in your case when you want to update just a few fields of a resource
Spring MVC added a support for it in the version 3.2, so you can do something like
#RequestMapping(value="/patch", method=RequestMethod.PATCH, consumes=MediaType.APPLICATION_JSON_VALUE)
public #ResponseBody String patch(#RequestBody Foo foo) {
return foo.toString();
}
and when sending the request, add only the properties you want to update to your PATCH request, the properties that are null or omited won't be updated
In the lack of better Spring MVC PATCH reference, I'm linking this SO thread as an interesting read Spring MVC PATCH method: partial updates
I'm working on a RESTful Web-service using Jersey v1.9.1. Some methods return JSON. When I want to Debug my application I start within a grizzly server, otherwise for production I build a war file and place it in a TomCat v7 installation. My projects are all Maven2 projects.
Now, I noticed that for a method that returns List<CustomObj>, where CustomObj has appropriate JAXB annotations, i.e. #XmlRootElement(name="CustomObj"), and getter/setters for all relevant members:
Using grizzly, I get something like {"CustomObj":[{<fields-of-customObj>},{<fields-of-customObj>},{<fields-of-customObj>}]} (when the list has 3 elements). Parsing this with GSON works fine.
Using TomCat, however, I get this: [{<fields-of-customObj>},{<fields-of-customObj>},{<fields-of-customObj>}] -> so as you can see, the "root" is missing somehow
I have the impression that the jersey-json module (which I included into my Maven2 dependencies) are not used at all in TomCat, even though they should be used (they are used in Grizzly for sure). Also, creating my own #Provider for a ContextResolver<JAXBContext> as described here only works in grizzly, in TomCat the getContext() method will never be called.
Is there anything I need to consider with TomCat?
Cheers!
My object gets serialised as {name="nyname" ....}, however, I require all keys to be start with uppercase, ie. {Name="myname",.....} how can I do that with Jackson ?
I had the same issue and posted about it earlier. I solved it here:
How can I enable Pascal casing by default when using Jackson JSON in Spring MVC?
If you're not using Spring, the answer would be similar. You'll still need a custom (de)serializer, and you'd just need to wire it in to your program in the manner you choose.