-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support to update OneToMany associations (#437)
* Adding support to update OneToMany associations * Additional test to account for already existing RestOneToManySerializer * Renaming OneToManySerializer to ReplaceAllSerializer Done to avoid confusion with already existing RestOneToManySerializer, which serializes OneToMany to JSON Arrays. * Bump version * Make ReadOnly annotation work by changing the property access
- Loading branch information
Showing
7 changed files
with
121 additions
and
26 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
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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/bullhornsdk/data/api/helper/json/replaceall/ReplaceAllModule.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,24 @@ | ||
package com.bullhornsdk.data.api.helper.json.replaceall; | ||
|
||
import com.bullhornsdk.data.model.entity.core.type.BullhornEntity; | ||
import com.bullhornsdk.data.model.entity.embedded.OneToMany; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
|
||
public class ReplaceAllModule extends SimpleModule { | ||
public ReplaceAllModule() { | ||
addSerializer((Class<OneToMany<? extends BullhornEntity>>) (Class<?>) OneToMany.class, new ReplaceAllSerializer()); | ||
|
||
} | ||
|
||
public String getModuleName() { | ||
return this.getClass().getSimpleName(); | ||
} | ||
|
||
public int hashCode() { | ||
return this.getClass().hashCode(); | ||
} | ||
|
||
public boolean equals(Object o) { | ||
return this == o; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/bullhornsdk/data/api/helper/json/replaceall/ReplaceAllSerializer.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,24 @@ | ||
package com.bullhornsdk.data.api.helper.json.replaceall; | ||
|
||
import com.bullhornsdk.data.model.entity.core.type.BullhornEntity; | ||
import com.bullhornsdk.data.model.entity.embedded.OneToMany; | ||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
|
||
import java.io.IOException; | ||
|
||
public class ReplaceAllSerializer extends StdSerializer<OneToMany<? extends BullhornEntity>> { | ||
protected ReplaceAllSerializer() { | ||
super((Class<OneToMany<? extends BullhornEntity>>) (Class<?>) OneToMany.class); | ||
} | ||
|
||
@Override | ||
public void serialize(OneToMany<? extends BullhornEntity> value, JsonGenerator gen, SerializerProvider provider) throws IOException { | ||
int[] ids = value.getData().stream().mapToInt(BullhornEntity::getId).toArray(); | ||
gen.writeStartObject(); | ||
gen.writeFieldName("replaceAll"); | ||
gen.writeArray(ids, 0, ids.length); | ||
gen.writeEndObject(); | ||
} | ||
} |
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,11 +1,16 @@ | ||
package com.bullhornsdk.data.util; | ||
|
||
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.METHOD) | ||
@Target({ElementType.METHOD, ElementType.FIELD}) | ||
@JacksonAnnotationsInside | ||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY) | ||
public @interface ReadOnly { | ||
} |
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