简体   繁体   中英

How to serialize a public static final string in a webservice?

Having this class:

public class Class1 implements Serializable
{
    public final static String  VALUE = "oneValue";
}

This class would be used in a Webservice.

In the webservice client I would like to:

String value = Class1.VALUE

Is there a way to serialize such public final static String so I can get the value in the webservice client?

I am using Axis2.

It is a class-level field, so the answer is no. If client code has different version of the class that has different value in given static field that is what they are going to get.

An enum could help you but any private field of the enum will not be visible to the client.

But, when the client sends an enum value to your web-service it will be mapped to your actual enum with all the private fields you have, and they will be usable server side.

The basic rule is that the client will not see any of your logic/default values. They only see getters and setters for your fields.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM