开发者

Returning an Enum from an EJB

开发者 https://www.devze.com 2023-03-14 11:34 出处:网络
I\'m looking to use Enum\'s to return both Codes and Messages from an EJB. Currently only an integer value Code is returned.

I'm looking to use Enum's to return both Codes and Messages from an EJB. Currently only an integer value Code is returned. As we have more than one client app and the clients are not always updated when the EJB common classes are and vica versa. What will happen if the Enum types on the Client side become out of sync?

Will it work if I have an old definition of an Enum on the client side, and a new definition on the EJB side and vica versa?

E.g Client side:

 public enum Color {
 WHITE(21, "White"), BLACK(22, "Black");

 private int code;
private int message;

 private Color(int c, String message) {
   code = c;
   message = m;
 }

 publi开发者_如何学Goc int getCode() {
   return code;
 }

public String getMessage(){
 return message;
}

EJB side:

 public enum Color {
 WHITE(21, "White"), BLACK(22, "Black"), RED(23, "Red");

 private int code;
private int message;

 private Color(int c, String message) {
   code = c;
   message = m;
 }

 public int getCode() {
   return code;
 }

public String getMessage(){
 return message;
}

And my EJB method is:

public Color getBestColor(); 

And returns:

Color.WHITE


If the client enum definition has the value you send, it will work fine (e.g. WHITE). if the client does not have the value, then you will get an IllegalArgumentException on the client side (e.g. RED). (details on enum serialization here).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号