user2041398
user2041398

Reputation: 1

json request enum

We have RestWS where need to pass request in JSON format. This request contains different type of values such as String, List, enum etc.

We figured out how need to pass String and List (see below) but not sure how to pass enum in JSON request object.

Sample JSON Request for List and String in request:

{"firstparam":["195","196"],"secondparam":"test"}

First param is List and second param is String. Similarly we need to know how we can pass enum (also in the above request).

Sample enum class:

@XmlType(name = "Type")
@XmlEnum
public enum Type {

@XmlEnumValue("New")
NEW("New"),
@XmlEnumValue("Delete")
DELETE("Delete"),
@XmlEnumValue("Process")
PROCESS("Process");
private final String value;

WorkingStatusType(String v) {
    value = v;
}

public String value() {
    return value;
}

public static WorkingStatusType fromValue(String v) {
    for (WorkingStatusType c: WorkingStatusType.values()) {
        if (c.value.equals(v)) {
            return c;
        }
    }
    throw new IllegalArgumentException(v);
}

Upvotes: 0

Views: 2285

Answers (1)

AlexSilva
AlexSilva

Reputation: 94

This Google JSON style guide might help you.

Upvotes: 2

Related Questions