When calling an instance of a waterline object via REST, the response does not contain any of the the instance methods defined in the waterline model. I read somewhere that when the object is written to JSON it strips off any methods. How can I stop this from happening? How can I make these instance methods available for usage in my front-end framework?
How can I stop this from happening?
You can't.
How can I make these instance methods available for usage in my
front-end framework?
You have to write actions that wrap the model instance methods and call them from your frontend.
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 am starting an Ember application from scratch that will connect to many non-standard JSON APIs which I don't control and from which I only need bits and pieces of data. My first attempt was to use jQuery alone but the code quickly became hard to read and maintain.
I want to use the Ember-Data RESTAdapter with some Serializers. I may need multiple Adapters and Serializers for the different APIs.
I am trying to figure out a good way to break down the work into logical steps.
What process should I follow?
For example:
"Start with what I need" approach:
Model ALL my objects using the FixtureAdapter as the ApplicationAdapter
Implement sample app using the models to ensure it's logically correct
Switch the FixtureAdapter for the RESTAdapter
Extend the RESTAdapter for each Model to map to the different APIs
Create a Serializer for each Model Adapter
-or-
"Start with what I can get" approach:
Extend a SINGLE ModelAdapter at a time, mapping it to the necessary API end-point
Create the Model for my ModelAdapter
Create the Serializer for that ModelAdapter
Implement model in the app
Repeat
Our project makes use of gilead to pass model objects to the client side using the GWT RPC model. The problem we face is that serializing to and from JSON on the client side for procesing is becoming more of an issue as our model grows / changes.
I am considering using Overlay Types as our client side representation of our entity objects.
What is the general approach for this when using it in conjunction with Hibernate, do you have to recreate the objects server side and then persist ?
Would it be possible to pass the client side object back and then use Dozer to map to the server side Entity ?
Thanks,
Andros
With Gilead and GWT-RPC, you don't need to translate your objects to JSON at all. You just pass your objects (entities which extend net.sf.gilead.pojo.gwt.LightEntity) to the client, and use them directly on the client. You can also send these objects from the client to the server. I would recommend to look at the Gilead example in this article:
http://code.google.com/webtoolkit/articles/using_gwt_with_hibernate.html
You can download the source code here:
http://google-web-toolkit.googlecode.com/files/gwt_hibernate_gilead.zip
We're using interfaces to represent entity classes in our domain model. We have concrete implementations of these by virtue of using LinqToSql. We have added a factory method to each LinqToSql class which our service layer uses to instantiate a new entity (note; as opposed to the controller's DataBind attribute doing it).
MonoRail's default DataBinder implementation will ignore properties that are defined as interfaces.
Ideally, we don't want to instantiate our data-layer classes in MonoRail - the whole point of the interfaces is to separate these concerns.
Also, we don't really want to create another set of non-LinqToSql concrete classes whose only job is to translate between layers.
It's the end of a really long day over here; please can someone have mercy and point us at the parts of IDataBinder that we should overload with our own implementations, or hint at other approaches we might attempt? ;-)
You should be looking at IParameterBinder. take a look at a post I've written on the subject
As Ken pointed, your idea could be implemented with a custom IParameterBinder.
A solution would be to use IOC:
resolve concrete instance of the form from it's interface
then use IDataBinder to bind the instance to the request params
Another one would be using IDictionaryAdapter:
generate a dto proxy for your interface
then use IDataBinder to bind the dto proxy instance to the request params
NB: second option won't work if interface:
is not public (hum)
has methods
or events
or readonly properties
or setonly properties
Last, I'm unsure of what is the problem exposing concrete class in controller's signature.
I myself use concrete form in controllers implementing interface defined in application layer services, it allows me to have concerns separated on both side:
controller side is Http mapping and first level data validation of the form/command
application layer services is business validation and processing of the form/command