Skip to content

Commit

Permalink
use copy instead of a constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
firestar committed Nov 11, 2023
1 parent e23696f commit 8184646
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/groovy/nucleodb.library.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = 'com.nucleodb'
version = '1.9.23'
version = '1.9.24'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nucleocore.library.database.modifications.Create;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -39,15 +41,12 @@ public DataEntry(Create create) throws ClassNotFoundException, JsonProcessingExc
}


public DataEntry(DataEntry toCopy) {
try {
for (Field field : DataEntry.class.getDeclaredFields()) {
if(field.isAnnotationPresent(SkipCopy.class)) continue;
field.set(this, field.get(toCopy));
}
}catch (Exception e){
e.printStackTrace();
}
public <T> T copy(Class<T> clazz) throws JsonProcessingException {
ObjectMapper om = new ObjectMapper()
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
.findAndRegisterModules()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return om.readValue(om.writeValueAsString(this), clazz);
}

public DataEntry() {
Expand Down

0 comments on commit 8184646

Please sign in to comment.