This commit is contained in:
crusader 2018-06-15 17:27:14 +09:00
parent c4704d6210
commit de27bebe66
5 changed files with 50 additions and 14 deletions

11
pom.xml
View File

@ -13,13 +13,13 @@
<groupId>com.loafle.overflow</groupId> <groupId>com.loafle.overflow</groupId>
<artifactId>commons-java</artifactId> <artifactId>commons-java</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.0.83-SNAPSHOT</version> <version>1.0.84-SNAPSHOT</version>
<name>com.loafle.overflow.commons-java</name> <name>com.loafle.overflow.commons-java</name>
<properties> <properties>
<commons.rpc-java.version>1.0.0-SNAPSHOT</commons.rpc-java.version> <commons.rpc-java.version>1.0.0-SNAPSHOT</commons.rpc-java.version>
<gson.version>2.8.2</gson.version> <jackson-databind.version>2.9.5</jackson-databind.version>
<spring.version>5.0.6.RELEASE</spring.version> <spring.version>5.0.6.RELEASE</spring.version>
<spring-data-commons.version>2.0.7.RELEASE</spring-data-commons.version> <spring-data-commons.version>2.0.7.RELEASE</spring-data-commons.version>
<hibernate.version>5.3.1.Final</hibernate.version> <hibernate.version>5.3.1.Final</hibernate.version>
@ -32,10 +32,11 @@
<version>${commons.rpc-java.version}</version> <version>${commons.rpc-java.version}</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency> <dependency>
<groupId>com.google.code.gson</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>gson</artifactId> <artifactId>jackson-databind</artifactId>
<version>${gson.version}</version> <version>${jackson-databind.version}</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->

View File

@ -0,0 +1,40 @@
package com.loafle.overflow.core.json;
import java.io.IOException;
import java.util.List;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.loafle.overflow.model.infra.InfraHostIP;
/**
* InfraHostIPsSerializer
*/
public class InfraHostIPsSerializer extends StdSerializer<List<InfraHostIP>> {
private static final long serialVersionUID = -7842189644539038488L;
public InfraHostIPsSerializer() {
this(null);
}
public InfraHostIPsSerializer(Class<List<InfraHostIP>> t) {
super(t);
}
@Override
public void serialize(List<InfraHostIP> infraHostIPs, JsonGenerator gen, SerializerProvider provider)
throws IOException {
if (null == infraHostIPs) {
return;
}
for (InfraHostIP infraHostIP : infraHostIPs) {
infraHostIP.setInfraHost(null);
}
gen.writeObject(infraHostIPs);
}
}

View File

@ -4,9 +4,10 @@ import java.util.List;
import javax.persistence.*; import javax.persistence.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.loafle.overflow.core.json.InfraHostIPsSerializer;
import com.loafle.overflow.model.meta.MetaTargetHostType; import com.loafle.overflow.model.meta.MetaTargetHostType;
import org.codehaus.jackson.annotate.JsonManagedReference;
import org.hibernate.annotations.Fetch; import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchMode;
@ -23,7 +24,7 @@ public class InfraHost extends Infra {
private InfraHostMachine infraHostMachine; private InfraHostMachine infraHostMachine;
private InfraHostOS infraHostOS; private InfraHostOS infraHostOS;
@JsonManagedReference @JsonSerialize(using = InfraHostIPsSerializer.class)
private List<InfraHostIP> infraHostIPs; private List<InfraHostIP> infraHostIPs;
private InfraHost containerInfraHost; private InfraHost containerInfraHost;

View File

@ -4,9 +4,6 @@ import javax.persistence.*;
import com.loafle.overflow.model.meta.MetaIPType; import com.loafle.overflow.model.meta.MetaIPType;
import org.codehaus.jackson.annotate.JsonBackReference;
import org.codehaus.jackson.annotate.JsonManagedReference;
import java.util.Date; import java.util.Date;
/** /**
@ -16,8 +13,6 @@ import java.util.Date;
@Table(name = "INFRA_HOST_IP", schema = "public") @Table(name = "INFRA_HOST_IP", schema = "public")
public class InfraHostIP { public class InfraHostIP {
private Long id; private Long id;
@JsonBackReference
@JsonManagedReference
private InfraHost infraHost; private InfraHost infraHost;
private MetaIPType metaIPType; private MetaIPType metaIPType;
private String address; private String address;

View File

@ -1,9 +1,8 @@
package com.loafle.overflow.model.member; package com.loafle.overflow.model.member;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.loafle.overflow.model.meta.MetaMemberStatus; import com.loafle.overflow.model.meta.MetaMemberStatus;
import org.codehaus.jackson.annotate.JsonIgnore;
import javax.persistence.*; import javax.persistence.*;
import java.util.Date; import java.util.Date;