Modified Message and its subclasses to work nicely with jackson

This commit is contained in:
Oskar Rasieński 2025-12-17 16:19:33 +01:00
commit e41dc70f97
7 changed files with 58 additions and 0 deletions

View file

@ -10,6 +10,8 @@ import commons.Ingredient;
public class CreateIngredientMessage implements Message {
private Ingredient ingredient;
public CreateIngredientMessage() {} // for jackson
public CreateIngredientMessage(Ingredient ingredient) {
this.ingredient = ingredient;
}
@ -27,4 +29,9 @@ public class CreateIngredientMessage implements Message {
public Ingredient getIngredient() {
return ingredient;
}
// for jackson
public void setIngredient(Ingredient ingredient) {
this.ingredient = ingredient;
}
}

View file

@ -10,6 +10,8 @@ import commons.Recipe;
public class CreateRecipeMessage implements Message {
private Recipe recipe;
public CreateRecipeMessage() {} // for jackson
public CreateRecipeMessage(Recipe recipe) {
this.recipe = recipe;
}
@ -27,4 +29,9 @@ public class CreateRecipeMessage implements Message {
public Recipe getRecipe() {
return recipe;
}
// for jackson
public void setRecipe(Recipe recipe) {
this.recipe = recipe;
}
}

View file

@ -8,6 +8,8 @@ package commons.ws.messages;
public class DeleteIngredientMessage implements Message {
private Long ingredientId;
public DeleteIngredientMessage() {} // for jackson
public DeleteIngredientMessage(Long ingredientId) {
this.ingredientId = ingredientId;
}
@ -25,4 +27,9 @@ public class DeleteIngredientMessage implements Message {
public Long getIngredientId() {
return ingredientId;
}
// for jackson
public void setIngredientId(Long ingredientId) {
this.ingredientId = ingredientId;
}
}

View file

@ -8,6 +8,8 @@ package commons.ws.messages;
public class DeleteRecipeMessage implements Message {
private Long recipeId;
public DeleteRecipeMessage() {} // for jackson
public DeleteRecipeMessage(Long recipeId) {
this.recipeId = recipeId;
}
@ -25,4 +27,9 @@ public class DeleteRecipeMessage implements Message {
public Long getRecipeId() {
return recipeId;
}
// for jackson
public void setRecipeId(Long recipeId) {
this.recipeId = recipeId;
}
}

View file

@ -1,5 +1,21 @@
package commons.ws.messages;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "type"
)
@JsonSubTypes({
@JsonSubTypes.Type(value = CreateRecipeMessage.class, name = "RECIPE_CREATE"),
@JsonSubTypes.Type(value = UpdateRecipeMessage.class, name = "RECIPE_UPDATE"),
@JsonSubTypes.Type(value = DeleteRecipeMessage.class, name = "RECIPE_DELETE"),
@JsonSubTypes.Type(value = CreateIngredientMessage.class, name = "INGREDIENT_CREATE"),
@JsonSubTypes.Type(value = UpdateIngredientMessage.class, name = "INGREDIENT_UPDATE"),
@JsonSubTypes.Type(value = DeleteIngredientMessage.class, name = "INGREDIENT_DELETE")
})
public interface Message {
public enum Type {
/**

View file

@ -10,6 +10,8 @@ import commons.Ingredient;
public class UpdateIngredientMessage implements Message {
private Ingredient ingredient;
public UpdateIngredientMessage() {} // for jackson
public UpdateIngredientMessage(Ingredient ingredient) {
this.ingredient = ingredient;
}
@ -27,4 +29,9 @@ public class UpdateIngredientMessage implements Message {
public Ingredient getIngredient() {
return ingredient;
}
// for jackson
public void setIngredient(Ingredient ingredient) {
this.ingredient = ingredient;
}
}

View file

@ -10,6 +10,8 @@ import commons.Recipe;
public class UpdateRecipeMessage implements Message {
private Recipe recipe;
public UpdateRecipeMessage() {} // for jackson
public UpdateRecipeMessage(Recipe recipe) {
this.recipe = recipe;
}
@ -27,4 +29,9 @@ public class UpdateRecipeMessage implements Message {
public Recipe getRecipe() {
return recipe;
}
// for jackson
public void setRecipe(Recipe recipe) {
this.recipe = recipe;
}
}