Lombok override error when building java project into jar - java

I'm having a spring java intellij project, where I wish to build the project as a jar file.
When I'm building, it says that this #Getter is not compatible with string type, but it is an enum. It also says that it is overriding, but I'm never doing that.
#Getter #Setter
private Status _status;
The complete error description is:
java: get_status() in <directive>.models.users.sub_users.subscriptions.Subscription cannot override get_status() in <directive>.models.Model
return type <directive>.models.users.sub_users.subscriptions.Subscription.Status is not compatible with java.lang.String
It is an annoying error and it works fine with other enums.
If you wish, here is the whole class:
/**
* Defines the kind of subscription a user is having.
* Only Artists and Bands can have a paying subscription.
*/
#ToString
public class Subscription extends Model {
/**
* The User that uses this Subscription.
*/
#Getter
private User _user;
/**
* An enum that contains different kinds of types, that this Subscription can be.
* Will also determine the price.
*/
#Getter
private Type _type;
/**
* An enum that determines what kind of status, the situation of the Subscription is in.
*/
#Getter #Setter
private Status _status;
/**
* How much the User should pay per month.
*/
private int _price;
/**
* An object class that specifies the offer if any, that this Subscription has.
*/
#Getter #Setter
private SubscriptionOffer _offer;
/**
* The id in the database of the card, that is connected to this subscription.
* Is only the id and not the object for security reasons.
*/
#Getter
private Long _cardId;
public Subscription(User user, Type type, Status status, SubscriptionOffer offer, Long cardId, LocalDateTime timestamp) {
super(user.get_primaryId(), cardId, user.get_username()+"-Subscription: " + user.get_primaryId(), timestamp);
_type = defineType(type);
_status = status;
_offer = offer;
_cardId = cardId;
}
public Subscription(long id, Type type, Status status, SubscriptionOffer offer, Long cardId) {
super(id, cardId, "Unkown_user-Subscription: " + id);
_type = defineType(type);
_status = status;
_offer = offer;
_cardId = cardId;
_timestamp = null;
}
public Subscription(User user, Type type, Status status, SubscriptionOffer offer, Long cardId) {
super(user.get_title() + "-Subscription");
_user = user;
_type = defineType(type);
_status = status;
_offer = offer;
_cardId = cardId;
}
/**
* Set the id of the card, that is connection to this Subscription,
* but will only do so, if the id is not already set.
* #param id The id value that will be set as the connection between this subscription and the card of that id.
* #return The id of the card, that is connected to this Subscription.
*/
public Long set_cardId(long id) {
if (_cardId==null)
_cardId = id;
return _cardId;
}
/**
* This is only meant to be used in User class after assemble.
* Will only set the User, if the User is null.
* #param user The User that will be set for this Subscription.
* #return The User of this Subscription.
*/
public User set_user(User user) {
if (user == null)
_user = user;
return _user;
}
/**
* Uses the defineType() method to set the type and also the price from the new type value.
* #param type An enum of a SubscriptionType, that is wished to be set.
* #return The SubscriptionType of this Subscription.
*/
public Type set_type(Type type) { return defineType(type); }
/**
* Sets the type of this Subscription and also determines the price for that type of Subscription.
* #param type An enum of a type of Subscription, that is wished to be set.
* #return This Subscription's type as the enum.
*/
private Type defineType(Type type) {
_type = type;
if (_user.getClass() != Artist.class && _user.getClass() != Band.class) {
switch (_type) {
case PREMIUM_BAND -> {
if (_user.getClass() == Band.class) _price = 100;
}
case PREMIUM_ARTIST -> {
if (_user.getClass() == Artist.class && ((Artist) _user).get_bands().size() == 0) _price = 60;
}
default -> _price = 0;
}
}
return _type;
}
/**
* Checks if there is a free trial offer or the User is either a Band or Artist,
* since they are the only paying Users.
* Also calculates the Offer effect with the price.
*
* #return The price per month of the User as a double, since it is multiplied with the Offer effect.
*/
public double get_price() {
if (_user != null &&
((_user.getClass() == Band.class || _user.getClass() == Artist.class) &&
(_offer.get_type() != SubscriptionOffer.Type.FREE_TRIAL && !isOfferExpired())))
return isOfferExpired() ? _price : _price * _offer.get_effect();
else return 0;
}
/**
* Determines whether the date that this offer's date has been reached or not.
* Counts from LocalDateTime.now.
* #return True if the moment now is after the date that the offer of this Subscription will expire, otherwise false.
*/
public boolean isOfferExpired() { return LocalDateTime.now().isAfter(_offer.get_expires()); }
/**
* An enum that can be of different types, determining the type of Subscription.
*/
public enum Type {
FREEMIUM,
PREMIUM_BAND,
PREMIUM_ARTIST
}
/**
* An enum that defines Status that a Subscription is currently in.
*/
public enum Status {
ACCEPTED,
BLOCKED,
DISACTIVATED,
CLOSED
}
}

Sorry, found out that in the superclass Model I had another field called _status, that was a string type, which caused the problem. My bad.

Related

Database column keeps reverting to null

hard facts:
<spring-boot.version>2.4.4</spring-boot.version>
<jhipster-dependencies.version>7.0.1</jhipster-dependencies.version>
<hibernate.version>5.4.29.Final</hibernate.version>
<liquibase.version>4.3.2</liquibase.version>
<liquibase-hibernate5.version>4.3.2</liquibase-hibernate5.version>
Database is postgresql 13.
My problem:
I am developing a platform where games can register to get access to other third party APIs. For this I have the class Game:
**
* A Game.
*/
#Entity
#Table(name = "game")
#Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Game implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
#SequenceGenerator(name = "sequenceGenerator")
private Long id;
#Column(name = "name")
private String name;
#Column(name = "description")
private String description;
#Column(name = "api_key")
private UUID apiKey;
#Column(name = "api_secret")
private UUID apiSecret;
....
The api_secret is to be kept secret, so it is only shown when the game is first created and otherwise always returned as null.
In irregular intervals, however, all api_secrets in my database are set to null, which then of course leads to access errors in the games.
Following relevant code snippets:
GameService:
/**
* Save a game.
*
* #param game the entity to save.
* #return the persisted entity.
*/
public Game save(Game game) {
log.debug("Request to save Game : {}", game);
game = createApiCredentials(game);
game.setUserExtra(userExtraService.findOne(getCurrentLoggedInUserId()).get());
return gameRepository.save(game);
}
/**
* Get all the games.
*
* #return the list of entities.
*/
#Transactional(readOnly = true)
public List<Game> findAll() {
log.debug("Request to get all Games");
List<Game> returnList = gameRepository.findAll();
for (Game game : returnList) {
game.setApiSecret(null);
}
return returnList;
}
/**
* Get one game by id.
*
* #param id the id of the entity.
* #return the entity.
*/
#Transactional(readOnly = true)
public Optional<Game> findOne(Long id) {
log.debug("Request to get Game : {}", id);
Optional<Game> returnGame = gameRepository.findById(id);
returnGame.get().setApiSecret(null);
return returnGame;
}
/**
* Get all the games associated to logged in user.
*
* #return the list of entities.
*/
#Transactional(readOnly = true)
public List<Game> findAllByAuthenticatedUser() {
log.debug("Request to get all Games");
List<Game> returnList = gameRepository.findAllByUserExtra(userExtraService.findOne(getCurrentLoggedInUserId()).get());
for (Game game : returnList) {
game.setApiSecret(null);
}
return returnList;
}
/**
* Generate new Api-Secret for game.
*
* #param id the id of the entity.
* #return the entity.
*/
public Game findOneAndGenerateNewApiSecret(Long id) {
log.debug("Request to get Game : {}", id);
Game returnGame = gameRepository.findById(id).get();
returnGame.setApiSecret(UUID.randomUUID());
return gameRepository.save(returnGame);
}
/**
* Delete the game by id.
*
* #param id the id of the entity.
*/
public void delete(Long id) {
log.debug("Request to delete Game : {}", id);
gameRepository.deleteById(id);
}
public boolean isGameRegistered(UUID apiKey, UUID apiSecret) {
if (gameRepository.findByApiKeyAndApiSecret(apiKey, apiSecret) != null) {
return true;
}
return false;
}
public Game createApiCredentials(Game game) {
UUID apiKey = UUID.randomUUID();
UUID apiSecret = UUID.randomUUID();
game.setApiKey(apiKey);
game.setApiSecret(apiSecret);
return game;
}
As you can see, there are many instances, where I set the apiSecret value to null, but in my opinion only when I return it to the user. And never do I call some save method.
GameRepository:
/**
* Spring Data SQL repository for the Game entity.
*/
#SuppressWarnings("unused")
#Repository
public interface GameRepository extends JpaRepository<Game, Long> {
public Game findByApiKeyAndApiSecret(UUID apiKey, UUID apiSecret);
public Game findByApiKey(UUID apiKey);
public List<Game> findAllByUserExtra(UserExtra userExtra);
}
On the database, I have set up a trigger that records every change in the games table. Here I also see that a change is made by my programmatic user. That means it is not a manual intervention either, but really happens by the program.
Trigger logging:
public | game | dbadmin | 2021-08-29 11:02:13.084959+02 | U | (5251,"GameName",,,,,gameKey,,00ucvnehiOJ85kZ3N5d5) | (5251,"GameName",,,,,gameKey,,,00ucvnehiOJ85kZ3N5d5) | update game set api_key=$1, api_secret=$2, description=$4, name=$6 where id=$10
Possibly someone discovers my error or are there still tricks, how I can narrow the problem further?

Hide value in sub class during creation of JSON

I have one class SyncRegistrationDto which have 8 fields , and i have a subclass SyncRegistrationFailureDto (super class SyncRegistrationDto ) which have two fields only . so while returning the object of sub class also i am getting the super class variable value as a null in json data.
Super Class:
public class SyncRegistrationDto implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -3922338139042373367L;
/** The registration id. */
private String registrationId;
/** The sync type dto. */
private SyncTypeDto syncType;
/** The parent registration id. */
private String parentRegistrationId;
/** The sync status dto. */
private SyncStatusDto syncStatus;
/** The status comment. */
private String statusComment;
/** The lang code. */
private String langCode;
/** The is active. */
#ApiModelProperty(hidden = true)
private Boolean isActive;
/** The is deleted. */
#ApiModelProperty(hidden = true)
private Boolean isDeleted;
/**
* Instantiates a new sync registration dto.
*/
public SyncRegistrationDto() {
super();
}
/**
* Instantiates a new sync registration dto.
*
* #param registrationId
* the registration id
* #param syncTypeDto
* the sync type dto
* #param parentRegistrationId
* the parent registration id
* #param syncStatusDto
* the sync status dto
* #param statusComment
* the status comment
* #param langCode
* the lang code
*/
public SyncRegistrationDto(String registrationId, SyncTypeDto syncTypeDto, String parentRegistrationId,
SyncStatusDto syncStatusDto, String statusComment, String langCode) {
super();
this.registrationId = registrationId;
this.syncType = syncTypeDto;
this.parentRegistrationId = parentRegistrationId;
this.syncStatus = syncStatusDto;
this.statusComment = statusComment;
this.langCode = langCode;
}
/**
* Gets the registration id.
*
* #return the registration id
*/
public String getRegistrationId() {
return registrationId;
}
/**
* Sets the registration id.
*
* #param registrationId
* the new registration id
*/
public void setRegistrationId(String registrationId) {
this.registrationId = registrationId;
}
/**
* Gets the parent registration id.
*
* #return the parent registration id
*/
public String getParentRegistrationId() {
return parentRegistrationId;
}
/**
* Sets the parent registration id.
*
* #param parentRegistrationId
* the new parent registration id
*/
public void setParentRegistrationId(String parentRegistrationId) {
this.parentRegistrationId = parentRegistrationId;
}
/**
* Gets the status comment.
*
* #return the status comment
*/
public String getStatusComment() {
return statusComment;
}
/**
* Sets the status comment.
*
* #param statusComment
* the new status comment
*/
public void setStatusComment(String statusComment) {
this.statusComment = statusComment;
}
/**
* Gets the lang code.
*
* #return the lang code
*/
public String getLangCode() {
return langCode;
}
/**
* Sets the lang code.
*
* #param langCode
* the new lang code
*/
public void setLangCode(String langCode) {
this.langCode = langCode;
}
/**
* Gets the checks if is active.
*
* #return the checks if is active
*/
public Boolean getIsActive() {
return isActive;
}
/**
* Sets the checks if is active.
*
* #param isActive
* the new checks if is active
*/
public void setIsActive(Boolean isActive) {
this.isActive = isActive;
}
/**
* Gets the sync type dto.
*
* #return the sync type dto
*/
public SyncTypeDto getSyncType() {
return syncType;
}
/**
* Sets the sync type dto.
*
* #param syncTypeDto
* the new sync type dto
*/
public void setSyncType(SyncTypeDto syncTypeDto) {
this.syncType = syncTypeDto;
}
/**
* Gets the sync status dto.
*
* #return the sync status dto
*/
public SyncStatusDto getSyncStatus() {
return syncStatus;
}
/**
* Sets the sync status dto.
*
* #param syncStatusDto
* the new sync status dto
*/
public void setSyncStatus(SyncStatusDto syncStatusDto) {
this.syncStatus = syncStatusDto;
}
/**
* Gets the checks if is deleted.
*
* #return the checks if is deleted
*/
public Boolean getIsDeleted() {
return isDeleted;
}
/**
* Sets the checks if is deleted.
*
* #param isDeleted
* the new checks if is deleted
*/
public void setIsDeleted(Boolean isDeleted) {
this.isDeleted = isDeleted;
}
Sub class:
public class SyncRegistrationFailureDto extends SyncRegistrationDto implements Serializable {
private static final long serialVersionUID = 4456270091048678274L;
private String registrationId;
private String messgae;
#Override
public String getRegistrationId() {
return registrationId;
}
#Override
public void setRegistrationId(String registrationId) {
this.registrationId = registrationId;
}
public String getMessgae() {
return messgae;
}
public void setMessgae(String messgae) {
this.messgae = messgae;
}
public SyncRegistrationFailureDto(String registrationId,String messgae) {
this.registrationId = registrationId;
this.messgae = messgae;
}
public SyncRegistrationFailureDto() {
super();
}
}
so while returning subclass object also i am getting variable of super class but i want only two value which is available in subclass how i can achieve it?
{
"registrationId": "12345",
"syncType": null,
"parentRegistrationId": null,
"syncStatus": null,
"statusComment": null,
"langCode": null,
"isActive": null,
"isDeleted": null,
"messgae": "Not active or not valid"
}
expected o/p:
{
"registrationId": "12345",
"messgae": "Not active or not valid"
}
thanks in Advance.
Simple solution would be to use #JsonInclude(Include.NON_NULL)

Retrofit - How to get response from JSON objects

I need to get a list of reviews using Retrofit from the following api query:
http://api.themoviedb.org/3/movie/{id}/reviews?api_key=#######
The JSON returned is:
{"id":83542,"page":1,"results":[{"id":"51910979760ee320eb020fc2","author":"Andres Gomez","content":"Interesting film with an exceptional cast, fantastic performances and characterizations. The story, though, is a bit difficult to follow and, in the end, seems to not have a real point.","url":"https://www.themoviedb.org/review/51910979760ee320eb020fc2"},{"id":"520a8d10760ee32c8718e6c2","author":"Travis Bell","content":"Cloud Atlas was a very well made movie but unlike most of the \"simultaneous stories that all come together at the end\" type of movies, this one just didn't. I'm still unclear as to the point of it all.\r\n\r\nAnother issue I had was a general feeling of goofiness. Sure, the Cavendish story was pure comedy but the rest of the stories just didn't feel serious enough to me.\r\n\r\nIt carried my attention for the 172 minutes well enough and it was entertaining. I just expected more of a pay off at the end.\r\n\r\nAll in all, it's definitely worth seeing but I still haven't made up my mind if I truly liked it or not. What did you think?","url":"https://www.themoviedb.org/review/520a8d10760ee32c8718e6c2"}],"total_pages":1,"total_results":2}
My goal is to to access the "content" attribute and then put in a TextView.
Where I am having trouble is, for some reason I cannot figure out how to return a list of result objects from the above JSON and then access the content attribute using getContent().
I think there may be a problem with the way I am using my model object/s? Should they be two seperate objects? I'm not sure. When I try to print out the objects I get empty responses...
Any help would be great.
Retrofit interface code is:
public class MovieService {
public interface MovieDbApi {
#GET("/3/movie/{id}?&append_to_response=reviews")
Call<MovieReview> getReviews(
#Path("id") int id,
#Query("api_key") String apiKey);
}
}
Model object code is:
POJO 1
public class MovieReview {
#SerializedName("id")
#Expose
private int id;
#SerializedName("page")
#Expose
private int page;
#SerializedName("results")
#Expose
private List<MovieReviewDetail> results = new ArrayList<MovieReviewDetail>();
#SerializedName("total_pages")
#Expose
private int totalPages;
#SerializedName("total_results")
#Expose
private int totalResults;
/**
*
* #return
* The id
*/
public int getId() {
return id;
}
/**
*
* #param id
* The id
*/
public void setId(int id) {
this.id = id;
}
/**
*
* #return
* The page
*/
public int getPage() {
return page;
}
/**
*
* #param page
* The page
*/
public void setPage(int page) {
this.page = page;
}
/**
*
* #return
* The results
*/
public List<MovieReviewDetail> getResults() {
return results;
}
/**
*
* #param results
* The results
*/
public void setResults(List<MovieReviewDetail> results) {
this.results = results;
}
/**
*
* #return
* The totalPages
*/
public int getTotalPages() {
return totalPages;
}
/**
*
* #param totalPages
* The total_pages
*/
public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}
/**
*
* #return
* The totalResults
*/
public int getTotalResults() {
return totalResults;
}
/**
*
* #param totalResults
* The total_results
*/
public void setTotalResults(int totalResults) {
this.totalResults = totalResults;
}
}
POJO 2
public class MovieReviewDetail {
#SerializedName("id")
#Expose
private int id;
#SerializedName("author")
#Expose
private String author;
#SerializedName("content")
#Expose
private String content;
#SerializedName("url")
#Expose
private String url;
/**
*
* #return
* The id
*/
public int getId() {
return id;
}
/**
*
* #param id
* The id
*/
public void setId(int id) {
this.id = id;
}
/**
*
* #return
* The author
*/
public String getAuthor() {
return author;
}
/**
*
* #param author
* The author
*/
public void setAuthor(String author) {
this.author = author;
}
/**
*
* #return
* The content
*/
public String getContent() {
return content;
}
/**
*
* #param content
* The content
*/
public void setContent(String content) {
this.content = content;
}
/**
*
* #return
* The url
*/
public String getUrl() {
return url;
}
/**
*
* #param url
* The url
*/
public void setUrl(String url) {
this.url = url;
}
}
Fragment code:
private static final String API_KEY = "#####";
private static final String API_BASE_URL_MOVIES = "http://api.themoviedb.org/";
private Call<MovieReview> call;
private MovieReview movieReview;
private List <MovieReviewDetail> movieReviewDetails;
public void getMovieReview(int id){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_BASE_URL_MOVIES)
.addConverterFactory(GsonConverterFactory.create())
.build();
MovieService.MovieDbApi movieDbApi = retrofit.create(MovieService.MovieDbApi.class);
call = movieDbApi.getReviews(id, API_KEY);
call.enqueue(new Callback<MovieReview>() {
#Override
public void onResponse(Response<MovieReview> response) {
if (!response.isSuccess()) {
Log.d(LOG_TAG, "Error");
}
movieReview = response.body();
movieReviewDetails = movieReview.getResults();
//Print out results
for (int i = 0; i < movieReviewDetails.size(); i++) {
System.out.println(movieReviewDetails.get(i).getContent());
}
}
#Override
public void onFailure(Throwable t) {
Log.e("Throwable: ", t.getMessage());
}
});
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
getMovieReview(83542);
}
I don't know why people type incorrect JSON response and then expect problems not to happen. Did you even bother to post the entire JSON response this is the response you get.
{"adult":false,"backdrop_path":"/2ZA03KiD4jePTNBTJjGGFTNQPMA.jpg","belongs_to_collection":null,"budget":102000000,"genres":[{"id":18,"name":"Drama"},{"id":878,"name":"Science Fiction"}],"homepage":"http://cloudatlas.warnerbros.com/","id":83542,"imdb_id":"tt1371111","original_language":"en","original_title":"Cloud Atlas","overview":"A set of six nested stories spanning time between the 19th century and a distant post-apocalyptic future. Cloud Atlas explores how the actions and consequences of individual lives impact one another throughout the past, the present and the future. Action, mystery and romance weave through the story as one soul is shaped from a killer into a hero and a single act of kindness ripples across centuries to inspire a revolution in the distant future. Based on the award winning novel by David Mitchell. Directed by Tom Tykwer and the Wachowskis.","popularity":3.552761,"poster_path":"/8VNiyIp67ZxhpNgdrwACW0jgvP2.jpg","production_companies":[{"name":"Anarchos Productions","id":450},{"name":"X-Filme Creative Pool","id":1972},{"name":"Ascension Pictures","id":7829},{"name":"ARD Degeto Film","id":10947},{"name":"Cloud Atlas Productions","id":11080},{"name":"Five Drops","id":11082},{"name":"Media Asia Group","id":11083},{"name":"Dreams of Dragon Picture","id":19621}],"production_countries":[{"iso_3166_1":"DE","name":"Germany"},{"iso_3166_1":"HK","name":"Hong Kong"},{"iso_3166_1":"SG","name":"Singapore"},{"iso_3166_1":"US","name":"United States of America"}],"release_date":"2012-10-26","revenue":130482868,"runtime":172,"spoken_languages":[{"iso_639_1":"en","name":"English"}],"status":"Released","tagline":"Everything is Connected","title":"Cloud Atlas","video":false,"vote_average":6.4,"vote_count":1774,"reviews":{"page":1,"results":[{"id":"51910979760ee320eb020fc2","author":"Andres Gomez","content":"Interesting film with an exceptional cast, fantastic performances and characterizations. The story, though, is a bit difficult to follow and, in the end, seems to not have a real point.","url":"https://www.themoviedb.org/review/51910979760ee320eb020fc2"},{"id":"520a8d10760ee32c8718e6c2","author":"Travis Bell","content":"Cloud Atlas was a very well made movie but unlike most of the \"simultaneous stories that all come together at the end\" type of movies, this one just didn't. I'm still unclear as to the point of it all.\r\n\r\nAnother issue I had was a general feeling of goofiness. Sure, the Cavendish story was pure comedy but the rest of the stories just didn't feel serious enough to me.\r\n\r\nIt carried my attention for the 172 minutes well enough and it was entertaining. I just expected more of a pay off at the end.\r\n\r\nAll in all, it's definitely worth seeing but I still haven't made up my mind if I truly liked it or not. What did you think?","url":"https://www.themoviedb.org/review/520a8d10760ee32c8718e6c2"}],"total_pages":1,"total_results":2}}
Notice the fact that that you can't directly access the inner object. Your outer object is reviews. You must then create a POJO class depicting that.
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
/**
* Created by Ramandeep Singh on 17-03-2016.
*/
public class Reviews {
#SerializedName("reviews")
#Expose
private MovieReview reviews;
public Reviews() {
}
public MovieReview getReviews() {
return reviews;
}
public void setReviews(MovieReview reviews) {
this.reviews = reviews;
}
}
And furthermore, the ID is not Integer, it is string field.
Next time onwards type the correct and whole JSON response.
This is the method. After modification to service and utility
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_BASE_URL_MOVIES)
.addConverterFactory(GsonConverterFactory.create())
.build();
MovieService.MovieDbApi movieDbApi = retrofit.create(MovieService.MovieDbApi.class);
call = movieDbApi.getReviews(id, API_KEY);
call.enqueue(new Callback<Reviews>() {
#Override
public void onResponse(Call<Reviews> call, Response<Reviews> response) {
if (!response.isSuccessful()) {
System.out.println("Error");
}
reviews = response.body();
movieReview=reviews.getReviews();
movieReviewDetails = movieReview.getResults();
//Print out results
for (int i = 0; i < movieReviewDetails.size(); i++) {
System.out.println(movieReviewDetails.get(i).getContent());
}
}
#Override
public void onFailure(Call<Reviews> call, Throwable t) {
t.printStackTrace();
}
}
);
This is your service now.
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Path;
import retrofit2.http.Query;
/**
* Created by Ramandeep Singh on 17-03-2016.
*/
public class MovieService {
public interface MovieDbApi {
#GET("/3/movie/{id}?&append_to_response=reviews")
Call<Reviews> getReviews(
#Path("id") int id,
#Query("api_key") String apiKey);
}
}
This is the output you get.
Interesting film with an exceptional cast, fantastic performances and characterizations. The story, though, is a bit difficult to follow and, in the end, seems to not have a real point.
Cloud Atlas was a very well made movie but unlike most of the "simultaneous stories that all come together at the end" type of movies, this one just didn't. I'm still unclear as to the point of it all.
Another issue I had was a general feeling of goofiness. Sure, the Cavendish story was pure comedy but the rest of the stories just didn't feel serious enough to me.
It carried my attention for the 172 minutes well enough and it was entertaining. I just expected more of a pay off at the end.
All in all, it's definitely worth seeing but I still haven't made up my mind if I truly liked it or not. What did you think?
Give this a try, Instead of seperating get call and get call with enqueue.
call = movieDbApi.getReviews(id, API_KEY).enqueue(new Callback<MovieReview>() {
#Override
public void onResponse(Response<MovieReview> response) {
if (!response.isSuccess()) {
Log.d(LOG_TAG, "Error");
}
movieReview = response.body();
movieReviewDetails = movieReview.getResults();
//Print out results
for (int i = 0; i < movieReviewDetails.size(); i++) {
System.out.println(movieReviewDetails.get(i).getContent());
}
}
#Override
public void onFailure(Throwable t) {
Log.e("Throwable: ", t.getMessage());
}
});

JsonPath from a Field name

I am working on an orchestration service. The service basically is a platform to call multiple downstream services and pass the error returned by them. The problem is that the error field returned by downstream service is according to the json schema of that service.
e.g. -
"details": [
{
"field": "downstream_service.request.path.field_name"
}
]
My component however needs to return error in something like
"details": [
{
"field": "my_component/users/index/field_name"
}
]
I have java POJO object for the my_component and i need to get the json path for the field with name field_name.
How to get the json path of a field from a POJO or Json object? I am looking for existing libraries or frameworks.
USER POJO
public class User extends HATEOASEntity implements ResourceModel {
/**
* Credentials allowed by the user.
*
*/
#JsonProperty("credentials")
#Valid
private List<Credential> credentials = new ArrayList<Credential>();
/**
* The business information collected from the customer to create a business
* user.
*
*/
#JsonProperty("business_details")
#Valid
private BusinessDetails businessDetails;
}
BUSINESS DETAILS POJO
public class BusinessDetails {
/**
* contact details entered by user.
*
*/
#JsonProperty("phone_contacts")
#Valid
private List<Phone> phoneContacts = new ArrayList<Phone>();
/**
* addresses entered by user
*
*/
#JsonProperty("addresses")
#Valid
private List<Address> addresses = new ArrayList<Address>();
}
ADDRESS POJO
public class Address {
/**
* Reference Identifier
*
*/
#JsonProperty("id")
private String id;
/**
* type of the address
*
*/
#JsonProperty("type")
private Address.Type type;
/**
* line-1 of the address
*
*/
#JsonProperty("line1")
private String line1;
/**
* line-2 of the address
*
*/
#JsonProperty("line2")
private String line2;
}
My downstream service will tell me that the error is in Line_1. Have mapped Line_1 to line1 of my schema definition. How can i return user/business_details/addresses/line1 ?

After Calling web services - getting null value for some property

We are using CXF web services.
Scenario:
one service call is returing List<NoteDTO> .
Data was there NoteDTO but after calling web services method which is returing List
we are seeing null values in NoteDTO class.
there is no any kind of Exceptions in Logs also.
My understanding is there is convertion problem in Webservices.
public class NoteDTO {
/** The text of the note. */
private String text;
/** The date the note was created. */
private Date created;
/** The user who created the note. */
private UserDTO createdBy;
/** The date the note was last modified. */
private Date modified;
/** The last user to modify the note. */
private UserDTO modifiedBy;
private String wfStep;
public void setWfStep(String wfStep) {
this.wfStep = wfStep;
}
/**
* Default constructor for JAXB.
*/
public NoteDTO() {
}
/**
* Constructor taking basic values.
* #param text The text of the note.
* #param created The date created.
* #param createdBy The user who create the note.
*/
public NoteDTO(String text, Date created, UserDTO createdBy) {
this.text = text;
this.created = created;
this.createdBy = createdBy;
}
/**
* Getter for the text of the note.
* #return The text of the note.
*/
public String getText() {
return text;
}
/**
* Setter for the text of the note.
* #param text The text of the note.
*/
public void setText(String text) {
this.text = text;
}
/**
* Getter for the created date.
* #return The created date.
*/
public Date getCreated() {
return created;
}
/**
* Setter for the created date.
* #param created The create date.
*/
public void setCreated(Date created) {
this.created = created;
}
/**
* Getter for the modified date.
* #return The modified date.
*/
public Date getModified() {
return modified;
}
/**
* Setter for the modified date.
* #param modified The modified date.
*/
public void setModified(Date modified) {
this.modified = modified;
}
/**
* Getter for the created by user.
* #return The created by user.
*/
public UserDTO getCreatedBy() {
return createdBy;
}
/**
* Setter for the created by user.
* #param createdBy The created by user.
*/
public void setCreatedBy(UserDTO createdBy) {
this.createdBy = createdBy;
}
/**
* Getter for the modified by user.
* #return The modified by user.
*/
public UserDTO getModifiedBy() {
return modifiedBy;
}
/**
* Setter for the modified by user.
* #param modifiedBy The modified by user.
*/
public void setModifiedBy(UserDTO modifiedBy) {
this.modifiedBy = modifiedBy;
}
/**
* Getter for the workflow step.
* #return The workflow step.
*/
public String getWfstep() {
return this.wfStep;
}
I have a web services class
#WebService
public interface NotesService {
/**
* Get server notes for a specific workflow instance
* #param workflowInstanceEntitityId Workflow Instance Entity ID
* #return A list of notes.
*/
List<NoteDTO> getNotesForWorkflowInstance(String bundleName, String workflowInstanceName);
}
the data was there at other side in NoteDTO but after call like below
notes = notesService.getNotesForWorkflowInstance(bundleName, workflowInstanceName);
I am getting wfStep property value as null
Any thoughts?
thansk in advance.
may be #WebMethod annotation will help?
You don't have the appropriate annotations on your classes so I assume you are using Java-First approach.
I am definitely sure that your NoteDTO is not the XSD schema of your WSDL types. If you are generating WSDL from java code using CXF what you need to do is to add the appropriate annotations on the web service' objects. So your NoteDTO class should be something like this:
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "NoteDTO", propOrder = {
"text",
"created",
"createdBy",
"modified",
"modifiedBy",
"wfStep"
})
public class NoteDTO {
#XmlElement(name = "text")
private String text;
#XmlElement(name = "created")
private Date created;
#XmlElement(name = "createdBy")
private UserDTO createdBy;
#XmlElement(name = "modified")
private Date modified;
#XmlElement(name = "modifiedBy")
private UserDTO modifiedBy;
#XmlElement(name = "wfStep")
private String wfStep;
}
The same with UserDTO and any other objects used in your web services calls. Then your interface should look something like this:
#WebService(targetNamespace = "http://your.target.namespace/", name = "NotesService")
#XmlSeeAlso({ObjectFactory.class})
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface NotesService {
#WebResult(name = "getNotesForWorkflowInstanceResponse", targetNamespace = "http://your.target.namespace/")
#WebMethod(operationName = "getNotesForWorkflowInstance", action = "http://your.target.namespace/getNotesForWorkflowInstance")
public List<NoteDTO> getNotesForWorkflowInstance(
#WebParam(name = "bundleName", targetNamespace = "http://your.target.namespace/") String bundleName,
#WebParam(name = "workflowInstanceName", targetNamespace = "http://your.target.namespace/") String workflowInstanceName
);
}
Not tested, just added everything by hand. Read more about the Java-First approach and you'll find out what you're doing wrong. This is just a hint to get started.

Categories