Enums Spring Rest API列表

时间:2017-06-08 14:58:56

标签: java spring rest spring-boot enums

我正在制作一个rest API并尝试创建一个可嵌入实体的属性,这是一个枚举列表。

Schedule.java

import threading
import socket
import subprocess

global thread_count
thread_count = 0

def ClientListener(client, address):
    global thread_count
    global serve
    command = client.recv(1024)
    message = ""
    try:
        print "Command from " + str(address[0]), str(address[1]) + ":", command
        output = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        message = output.stdout.read()
        if message == "":
            message = output.stderr.read()
    except:
        message = "error occurred!"
    print "Message to be sent:", message
    client.send(message)
    client.close()
    thread_count -= 1

class ThreadServer:

    def __init__(self):
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.host = socket.gethostname()
        self.port = 2345
        self.sock.bind((self.host, self.port))

    def listen(self):
        global thread_count
        global serve
        self.sock.listen(1)
        while True:
            if thread_count < 3:
                client, address = self.sock.accept()
                print "Connection from %s with port %s" % (str(address[0]), str(address[1]))
                thread_count += 1
                print "thread Count:", thread_count
                threading.Thread(target=ClientListener, args=(client, address)).start()


ThreadServer().listen()

Task.java

@Embeddable
public class Schedule {
    @Enumerated(EnumType.STRING)
    @ElementCollection(targetClass = DayOfWeekEnum.class)
    private List<DayOfWeekEnum> daysOfWeek;

    public enum DayOfWeekEnum {
        SUNDAY,
        MONDAY,
        TUESDAY,
        WEDNESDAY,
        THURSDAY,
        FRIDAY,
        SATURDAY
    }

    //getters, setters, and constructors
}

我创建了一个任务实体,其中包含@Entity public class Task extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.AUTO) private final Long id; @NotNull(message = "Task description can not be null.") @NotBlank(message = "Task description can not be nothing.") private String description; @NotNull(message = "Task must either be completed or not.") private boolean complete; @Embedded private Schedule schedule; //getters, setters, and constructors } 填充了daysOfWeek的Schedule对象,但在其余API显示中,该属性为空。

DayOfWeekEnum.SUNDAY

为什么不显示以下内容?

"daysOfWeek": []

0 个答案:

没有答案