Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Management of the Json identity info annotation for class was added. #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
import javax.persistence.Version;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

import static co.jirm.core.util.JirmPrecondition.check;
import co.jirm.mapper.SqlObjectConfig;
Expand Down Expand Up @@ -117,6 +119,24 @@ public Object convertToSql(Object original) {

static Map<String, SqlParameterDefinition> getSqlBeanParameters(Class<?> k, SqlObjectConfig config) {
Map<String, SqlParameterDefinition> parameters = new LinkedHashMap<String, SqlParameterDefinition>();

final JsonIdentityInfo classIdentityInfo = k.getAnnotation(JsonIdentityInfo.class);
if (classIdentityInfo != null && classIdentityInfo.generator() == ObjectIdGenerators.IntSequenceGenerator.class) {
final String idName = classIdentityInfo.property();
final SqlParameterDefinition parameterDefinition = newSimpleInstance(
config.getConverter(),
idName,
Integer.class,
-1,
config.getNamingStrategy().propertyToColumnName(idName.replaceAll("^@", "meta_")),
true,
false,
true,
Optional.<Enumerated>absent());

parameters.put(idName, parameterDefinition);
}

Constructor<?> cons[] = k.getDeclaredConstructors();
for (Constructor<?> c : cons) {
JsonCreator jc = c.getAnnotation(JsonCreator.class);
Expand Down