-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filtering in recursive Initialization
Serialization brikule (now i know how to serialize ids instead of fetching)
- Loading branch information
Showing
7 changed files
with
100 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/cz/trailsthroughshadows/api/rest/jsonfilter/IncludeNullOrEmptySerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cz.trailsthroughshadows.api.rest.jsonfilter; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import jakarta.persistence.Persistence; | ||
import org.hibernate.proxy.HibernateProxy; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
|
||
public class IncludeNullOrEmptySerializer extends com.fasterxml.jackson.databind.JsonSerializer<Object> { | ||
@Override | ||
public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers) throws IOException { | ||
if (value == null) { | ||
gen.writeNull(); | ||
} else if (!Persistence.getPersistenceUtil().isLoaded(value)) { | ||
if (value instanceof Collection) { | ||
gen.writeStartArray(); | ||
for (Object o : (Collection) value) { | ||
gen.writeObject(o); | ||
} | ||
gen.writeEndArray(); | ||
} else { | ||
gen.writeObject(((HibernateProxy) value).getHibernateLazyInitializer().getIdentifier()); | ||
} | ||
} else { | ||
gen.writeObject(value); | ||
} | ||
} | ||
} |
15 changes: 13 additions & 2 deletions
15
src/main/java/cz/trailsthroughshadows/api/rest/jsonfilter/LazyFieldsFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
package cz.trailsthroughshadows.api.rest.jsonfilter; | ||
|
||
import jakarta.persistence.Persistence; | ||
import org.hibernate.proxy.HibernateProxy; | ||
|
||
import java.util.Collection; | ||
|
||
public class LazyFieldsFilter { | ||
@Override | ||
public boolean equals(Object obj) { | ||
|
||
if (obj == null) | ||
return true; | ||
return false; | ||
|
||
if (obj instanceof Collection) | ||
return false; | ||
|
||
// if (obj instanceof HibernateProxy) | ||
// return false; | ||
|
||
return !Persistence.getPersistenceUtil().isLoaded(obj); | ||
if (Persistence.getPersistenceUtil().isLoaded(obj)) | ||
return false; | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 11 additions & 6 deletions
17
src/main/java/cz/trailsthroughshadows/api/table/action/summon/SummonAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,47 @@ | ||
package cz.trailsthroughshadows.api.table.action.summon; | ||
|
||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import cz.trailsthroughshadows.api.rest.jsonfilter.LazyFieldsFilter; | ||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.io.Externalizable; | ||
import java.io.Serializable; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Entity | ||
@Table(name = "SummonAction") | ||
@JsonInclude(value = JsonInclude.Include.CUSTOM, valueFilter = LazyFieldsFilter.class) | ||
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) | ||
public class SummonAction { | ||
|
||
@EmbeddedId | ||
private SummonActionId id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@MapsId("summon_id") | ||
@MapsId("idSummon") | ||
@JoinColumn(name = "idSummon") | ||
private Summon summon; | ||
|
||
@Column(name = "idAction", insertable = false, updatable = false) | ||
private int idAction; | ||
|
||
@Column | ||
private Integer range; | ||
|
||
@Embeddable | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class SummonActionId implements Serializable { | ||
@Column(name = "idSummon") | ||
private Integer summon_id; | ||
private Integer idSummon; | ||
@Column(name = "idAction") | ||
private Integer action_id; | ||
private Integer idAction; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters