Java how to pass enum in postman body

Java how to pass enum in postman body

To pass an enum value in the body of a POST request using Postman, you can use the raw body type and specify the enum value as a string.

Here is an example of how you can pass an enum value in the body of a POST request using Postman:

  1. First, define an enum in your Java code:
‮t refer‬o:lautturi.com
public enum MyEnum {
    VALUE_1,
    VALUE_2,
    VALUE_3
}
  1. Next, create a POST request in Postman and select the raw body type.

  2. In the body of the request, enter the enum value as a string, surrounded by double quotes:

"VALUE_1"
  1. Send the request to the server.

On the server side, you can use the valueOf method of the MyEnum class to convert the string value to an enum value:

String str = request.getParameter("param");
MyEnum value = MyEnum.valueOf(str);

In this example, the str variable is initialized with the value of the param parameter from the request, and the valueOf method is used to convert the string value to an enum value.

Keep in mind that this is just one way to pass an enum value in the body of a POST request using Postman. You can use different methods and techniques to achieve the same result, such as using the fromValue method of the MyEnum class, or using a custom serialization and deserialization method to convert the enum value to a string and vice versa.

Created Time:2017-11-03 23:27:11  Author:lautturi