I'm currently facing a problem with Adobe Flash Builder, I work on a project with a Java core and services to communicate with a Flex client. (BlazeDS channel)
I decided to remove an array list in an object because it was no longer useful, so I commented the following lines in my object value to remove the ArrayList named "unitFactors"
public class UnitValue extends PhysicalQuantityObjectValue{
String symbol;
String name;
String description;
String physicalQuantityName;
//UnitFactorValue[] unitFactors;
UnitConstraintValue unitConstraint;
public UnitValue(AdnUnit unit) {
super(unit.getId());
//Constructor code ...
}
public UnitValue() {}
public String getSymbol() {
return symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPhysicalQuantityName() {
return physicalQuantityName;
}
public UnitValue(String symbol, String name, String description,
String physicalQuantityName,
UnitConstraintValue unitConstraint) {
super();
this.symbol = symbol;
this.name = name;
this.description = description;
this.physicalQuantityName = physicalQuantityName;
//this.unitFactors = unitFactors;
this.unitConstraint = unitConstraint;
}
public void setPhysicalQuantityName(String physicalQuantityName) {
this.physicalQuantityName = physicalQuantityName;
}
//public UnitFactorValue[] getUnitFactors() {
//return unitFactors;
//}
//public void setUnitFactors(UnitFactorValue[] unitFactors) {
//this.unitFactors = unitFactors;
//}
public UnitConstraintValue getUnitConstraint() {
return unitConstraint;
}
public void setUnitConstraint(UnitConstraintValue unitConstraint) {
this.unitConstraint = unitConstraint;
}
Well, no problem with the Java part. I tested it with SoapUI, everything's fine.
But when I switch on my Flex client code to refresh the valueObjects, it appears impossible to refresh UnitValue, unitFactors is still there, and it's obviously impossible to make my application work without errors on that specific point ... Can't find getUnitFactors().
Is someone facing the same problem with AdobeFlashBuilder?
Related
Im creating a Java application, I used enum to create movie category. When I input MovieCategory.WAR I would like to see War movie(My description) instead of WAR. How is it possible? I tried MovieCategory.WAR.getDescription() but does't work.
public enum MovieCategory {
COMEDY("Comedy"), HORROR("Horror"), SCIFI("Sci-Fi"),
ACTION("Action movie"), ROMANTIC("Romantic"),
CLASSIC("Classic"), WAR("War movie");
private final String description;
MovieCategory(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}
public class MovieManager {
private List<Movie> movieList;
public MovieManager() {
this.movieList = new ArrayList<>();
movieList.add(new Movie("Simple movie", MovieCategory.WAR,"Testing description.",167,12));
(...)
The enum works correctly:
public static void main(String[] args) {
// Displays: Comedy
System.out.println(COMEDY.getDescription());
// Displays: COMEDY
System.out.println(COMEDY);
}
Or, maybe you want the toString method to use description?
public enum MovieCategory {
COMEDY("Comedy");
private final String description;
MovieCategory(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
#Override
public String toString() {
return getDescription();
}
public static void main(String[] args) {
// Displays: Comedy
System.out.println(COMEDY.getDescription());
// Displays: Comedy
System.out.println(COMEDY);
}
}
UPDATE #3: It seems the issue is the JSON response. If you want the description to be returned, you can annotate the getDescription method wtih #JsonValue.
import com.fasterxml.jackson.annotation.JsonValue;
public enum MovieCategory {
WAR("War movie");
private final String description;
MovieCategory(String description) {
this.description = description;
}
#JsonValue
public String getDescription() {
return description;
}
#Override
public String toString() {
return getDescription();
}
public static void main(String[] args) {
// Displays: Comedy
System.out.println(WAR.getDescription());
// Displays: Comedy
System.out.println(WAR);
}
}
I noticed that my bot didn't set RichPresence any more than I looked at it today. The last time I checked it was on Wednesday and the code worked there as well. So I executed it again today and the RichPresence was not re-set as usual. Now I think Discord will have changed its interface.
Now I got the latest JDA version into my project and adapted the code so that the DataObject became a JSONObject and it still didn't work. As 2nd I tried to make my "Spielst" object a RichPresence object. Unfortunately, this didn't work either.
Old Class:
public class Spielst implements Activity {
private String name;
private String url;
private ActivityType type;
public static Spielst getSpielt(String name, String url, ActivityType typ){
return new Spielst(name,url,typ);
}
protected Spielst(String name, String url, ActivityType typ) {
this.name = name;
this.url = url;
this.type = typ;
}
#Override
public boolean isRich() {
return false;
}
#Override
public RichPresence asRichPresence() {
return null;
}
#Override
public String getName() {
return name;
}
#Override
public String getUrl() {
return url;
}
#Override
public ActivityType getType() {
return type;
}
#Nullable
#Override
public Timestamps getTimestamps() {
return null;
}
public void setPresence(OnlineStatus status, String state, String details, String application_id,
String large_image, String small_image, String large_text, String small_text,
long timestamp, long since){
if(Bot.getInstance().getBot() == null)
return;
PresenceImpl presence = new PresenceImpl((JDAImpl) Bot.getInstance().getBot()).setCacheActivity(this)
.setCacheStatus(status);
JSONObject data = presence.getFullPresence();
JSONObject game = data.getJSONObject("game");
game.put("state",state);
game.put("details", details);
game.put("application_id", application_id);
JSONObject assets = new JSONObject();
game.put("timestamps",new JSONObject().put("start",timestamp));
assets.put("large_image", large_image);
assets.put("small_image", small_image);
assets.put("large_text", large_text);
assets.put("small_text", small_text);
game.put("assets",assets);
game.put("since",since);
data.put("game",game);
((JDAImpl) Bot.getInstance().getBot())
.getClient().send((new JSONObject()).put("d", data).put("op", 3).toString());
System.out.println((new JSONObject()).put("d", data).put("op", 3).toString());
}
}
new Class:
package de.letsplaybar.discordbot.main.utils;
import de.letsplaybar.discordbot.main.Bot;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.ActivityFlag;
import net.dv8tion.jda.api.entities.RichPresence;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.EnumSet;
/**
* #author Letsplaybar
* Created on 05.09.2017.
*/
public class Spielst implements RichPresence {
private String name;
private String url;
private ActivityType type;
private OnlineStatus status;
private String state;
private String details;
private String application_id;
private String large_image;
private String small_image;
private String large_text;
private String small_text;
private long timestamp;
private long since;
public static Spielst getSpielt(String name, String url, ActivityType typ,OnlineStatus status, String state, String details, String application_id,
String large_image, String small_image, String large_text, String small_text,
long timestamp, long since){
return new Spielst(name,url,typ,status,state,details,application_id,large_image,small_image,large_text,small_text,timestamp, since);
}
protected Spielst(String name, String url, ActivityType typ,OnlineStatus status, String state, String details, String application_id,
String large_image, String small_image, String large_text, String small_text,
long timestamp, long since) {
this.name = name;
this.url = url;
this.type = typ;
}
#Override
public boolean isRich() {
return false;
}
#Override
public RichPresence asRichPresence() {
return null;
}
#Override
public String getName() {
return name;
}
#Override
public String getUrl() {
return url;
}
#Override
public ActivityType getType() {
return type;
}
#Nullable
#Override
public Timestamps getTimestamps() {
return null;
}
public void setPresence(){
Bot.getInstance().getBot().getPresence().setActivity(this);
}
#Override
public long getApplicationIdLong() {
return Long.parseLong(application_id);
}
#Nonnull
#Override
public String getApplicationId() {
return application_id;
}
#Nullable
#Override
public String getSessionId() {
return "4b2fdce12f639de8bfa7e3591b71a0d679d7c93f";
}
#Nullable
#Override
public String getSyncId() {
return "e7eb30d2ee025ed05c71ea495f770b76454ee4e0";
}
#Override
public int getFlags() {
return ActivityFlag.JOIN_REQUEST.getOffset();
}
public long getTimestamp() {
return timestamp;
}
public long getSince() {
return since;
}
#Override
public EnumSet<ActivityFlag> getFlagSet() {
return EnumSet.of(ActivityFlag.JOIN_REQUEST);
}
#Nullable
#Override
public String getState() {
return state;
}
#Nullable
#Override
public String getDetails() {
return details;
}
#Nullable
#Override
public Party getParty() {
return new Party("party1234", 1, 6);
}
#Nullable
#Override
public Image getLargeImage() {
return new Image(getApplicationIdLong(), large_image, large_text);
}
#Nullable
#Override
public Image getSmallImage() {
return new Image(getApplicationIdLong(), small_image, small_text);
}
}
but by the new class, I miss the syncid and the seasonid and I also don't know where I get them from, because they are not in the documentation on the discordwebsite. has anyone found an implementation that still works for the old version or does anyone know how to get to the two values?
JDA is library made for bot accounts. Since bots can't use rich presence at all it doesn't actually support setting it. Furthermore there is no real support by discord's API for setting it this way.
The correct way to use rich presence is through an IPC connection with the discord-rpc SDK or Game SDK.
You can use a java library for the discord-rpc SDK like java-discord-rpc which connects to your Discord client and sets the presence there.
Updating rich presence through the gateway session (like JDA uses) is not documented behavior and subject to change.
Bots can't have a rich presence. Sending a request manually to Discord won't help you. If you're selfbotting, that's against the Discord TOS.
trying to access JSON data from the following:
{"actions":[{"actionType":0,"email":"contact#tonyspizza.com","faIcon":"fa-envelope",
"name":"Contact Us","subject":"Email from Tony's Pizza App"},
{"actionType":2,"faIcon":"fa-phone","name":"Call Us","number":"5204558897"}],
"total":2}
I'm trying to use retrofit to access the 'actions' as each individual classes. (i.e. ActionEmail, ActionPhone, etc). I cannot figure out a way to separate these into separate classes and not have one class with all the properties.
Thanks in advance!
Call<ActionWrapperObject> getActions(// Put your api call body in there);
Here is your ActionWrapperObject
public class ActionWrapperObject {
ArrayList<ActionModel> actions;
public ArrayList<ActionModel> getActions() {
return actions;
}
public void setActions(ArrayList<ActionModel> actions) {
this.actions = actions;
}
}
Here is your ActionModel
public class ActionModel {
int actionType;
String email;
String faIcon;
String name;
String subject;
public int getActionType() {
return actionType;
}
public void setActionType(int actionType) {
this.actionType = actionType;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getFaIcon() {
return faIcon;
}
public void setFaIcon(String faIcon) {
this.faIcon = faIcon;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
}
You in your response
Your api call.enqueue(new Callback<ActionWrapperObject>() {
#Override
public void onResponse(Call<ActionWrapperObject> call, Response<ActionWrapperObject> response) {
ActionWrapperObject actionWrapperObj= response.body();
if (actionWrapperObj!= null) {
ArrayList<ActionModel> actionModelList= actionWrapperObj.getActions();
//Here you got the list of actions. Do what ever you want with them. You can
// differentiate each action on its type.
}
}
What I infer is you want to generate fields of the ActionModel class dynamically. You can refer to generating JSON pojo dynamically using reflection.
Here is the problem, when I send my object to server using retrofit I got it null. I'm doing this to create the json object:
HashMap<String, UserModel> map = new HashMap<>();
map.put("user", user);
But, when the json arrives in the server I got something like this:
{"user":null}
Then I printed ny json file with this line:
Log.d("TAG", new JSONObject(map).toString());
And I saw the same null object.
So, here is my question, Why is this happening? And how can I fix that?
Here goes some information about my project:
Retrofit version: 2.0.0
Retrofit serializer: jackson version 2.0.0
using also jackson to convert JodaTime version 2.4.0
here goes how I get retrofit instance:
public T buildServiceInstance(Class<T> clazz){
return new Retrofit.Builder().baseUrl(BuildConfig.API_HOST)
.addConverterFactory(JacksonConverterFactory.create())
.build().create(clazz);
}
I call that method here:
public static final IUserApi serviceInstance = new ApiBuildRequester<IUserApi>()
.buildServiceInstance(IUserApi.class);
Method declaration on interface IUserApi:
#POST("User.svc/Save")
Call<ResponseSaveUserApiModel> save(#Body HashMap<String, UserModel> map);
And at last, but I guess, not less important:
public class UserModel implements Parcelable {
private String idUser;
private String name;
private String email;
#JsonProperty("password")
private String safePassword;
private String salt;
private String phoneNumber;
private String facebookProfilePictureUrl;
private String facebookUserId;
public UserModel() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIdUser() {
return idUser;
}
public void setIdUser(String idUser) {
this.idUser = idUser;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getSafePassword() {
return safePassword;
}
public void setSafePassword(String safePassword) {
this.safePassword = safePassword;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getFacebookProfilePictureUrl() {
return facebookProfilePictureUrl;
}
public void setFacebookProfilePictureUrl(String facebookProfilePictureUrl) {
this.facebookProfilePictureUrl = facebookProfilePictureUrl;
}
public String getFacebookUserId() {
return facebookUserId;
}
public void setFacebookUserId(String facebookUserId) {
this.facebookUserId = facebookUserId;
}
#Override
public int describeContents() {
return 0;
}
public UserModel(Parcel in) { // Deve estar na mesma ordem do "writeToParcel"
setIdUser(in.readString());
setName(in.readString());
setEmail(in.readString());
setSafePassword(in.readString());
setPhoneNumber(in.readString());
setFacebookProfilePictureUrl(in.readString());
setFacebookUserId(in.readString());
}
#Override
public void writeToParcel(Parcel dest, int flags) { //Deve estar na mesma ordem do construtor que recebe parcel
dest.writeString(idUser);
dest.writeString(name);
dest.writeString(email);
dest.writeString(safePassword);
dest.writeString(phoneNumber);
dest.writeString(facebookProfilePictureUrl);
dest.writeString(facebookUserId);
}
public static final Parcelable.Creator<UserModel> CREATOR = new Parcelable.Creator<UserModel>(){
#Override
public UserModel createFromParcel(Parcel source) {
return new UserModel(source);
}
#Override
public UserModel[] newArray(int size) {
return new UserModel[size];
}
};
public String getSalt() {
return salt;
}
public void setSalt(String salt) {
this.salt = salt;
}
}
Debug screen:
#Selvin and #cricket_007 You are the best!
I got this using your hint that my printing was wrong, and I found the solution.
I have two types of users in my app, facebook users or native users, two forms, but just one object, and here was the problem, when I sent facebook objects (complete) it worked fine, but when I tried to send native users, with some null properties, it crashed my serialization.
So I had to check every property before send it, it's just a workaround, but for now it's enough, thank you a lot folks!
This question already has answers here:
Android:Passing a hash map between Activities
(5 answers)
Closed 3 years ago.
EDIT: I've updated my question considerably and am now going with Parcelable as my method.
I'm attempting to a pass an ArrayList from one activity to another. I've been reading around and can't seem to find any answers to my problem.
I've got an ArrayList<SearchList> which implements Parcelable SearchList has the following code...
public class SearchList implements Parcelable {
private String title;
private String description;
private String link;
public SearchList(String name, String phone, String mail) {
super();
this.title = name;
this.description = phone;
this.link = mail;
}
public SearchList(Parcel source){
/*
* Reconstruct from the Parcel
*/
title = source.readString();
description = source.readString();
link = source.readString();
}
public String gettitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getLink() {
return link;
}
public void setLink(String link) {
this.link = link;
}
public int describeContents() {
// TODO Auto-generated method stub
return 0;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(title);
dest.writeString(description);
dest.writeString(link);
}
public static final Creator<SearchList> CREATOR = new Creator<SearchList>() {
public SearchList createFromParcel(Parcel source) {
return new SearchList(source);
}
public SearchList[] newArray(int size) {
return new SearchList[size];
}
};
}
However, when I try and do...
List<SearchList> listOfResults = new ArrayList<SearchList>();
intent.putParcelableArrayListExtra("results", listOfResults);
I get not applicable for type (String, List<SearchList> why?
Could you use all String values, and change from bundle.putSerializable() to bundle.putStringArrayList("key", ArrayList<String>_object)
You can use SQLite as alternative. To pass data from one Activity to another. Here the link.