Serializier and Deserializer for Jackson processing ContactEntryKeys
parent
f8056cb421
commit
87e32f6657
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@librecms/ccm-cms",
|
||||
"version": "7.0.0-SNAPSHOT.2022-11-26T122815",
|
||||
"version": "7.0.0-SNAPSHOT.2022-12-01T192513",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@librecms/ccm-cms",
|
||||
"version": "7.0.0-SNAPSHOT.2022-11-26T122815",
|
||||
"version": "7.0.0-SNAPSHOT.2022-12-01T192513",
|
||||
"license": "LGPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"@tiptap/core": "^2.0.0-beta.127",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@librecms/ccm-cms",
|
||||
"version": "7.0.0-SNAPSHOT.2022-11-26T122815",
|
||||
"version": "7.0.0-SNAPSHOT.2022-12-01T192513",
|
||||
"description": "JavaScript stuff for ccm-cms",
|
||||
"main": "target/generated-resources/assets/@content-sections/cms-admin.js",
|
||||
"types": "target/generated-resources/assets/@content-sections/cms-admin.d.ts",
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import org.hibernate.envers.Audited;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -63,6 +65,8 @@ public class ContactEntry implements Serializable {
|
|||
// @Column(name = "ENTRY_KEY", length = 255, nullable = false)
|
||||
@OneToOne
|
||||
@JoinColumn(name = "CONTACT_ENTRY_KEY_ID")
|
||||
@JsonSerialize(using = ContactEntryKeyJsonSerializer.class)
|
||||
@JsonDeserialize(using = ContactEntryKeyJsonDeserializer.class)
|
||||
private ContactEntryKey key;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (C) 2022 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ContactEntryKeyJsonDeserializer
|
||||
extends JsonDeserializer<ContactEntryKey> {
|
||||
|
||||
@Override
|
||||
public ContactEntryKey deserialize(
|
||||
final JsonParser parser,
|
||||
final DeserializationContext ctxt
|
||||
) throws IOException, JsonProcessingException {
|
||||
final String key = parser.getText();
|
||||
|
||||
final ContactEntryKeyRepository entryKeyRepo = CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(ContactEntryKeyRepository.class);
|
||||
final Optional<ContactEntryKey> result = entryKeyRepo
|
||||
.findByEntryKey(key);
|
||||
|
||||
if (result.isPresent()) {
|
||||
return result.get();
|
||||
} else {
|
||||
final ContactEntryKey entryKey = new ContactEntryKey();
|
||||
entryKey.setEntryKey(key);
|
||||
entryKeyRepo.save(entryKey);
|
||||
|
||||
return entryKey;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (C) 2022 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ContactEntryKeyJsonSerializer
|
||||
extends JsonSerializer<ContactEntryKey> {
|
||||
|
||||
@Override
|
||||
public void serialize(
|
||||
final ContactEntryKey value,
|
||||
final JsonGenerator generator,
|
||||
final SerializerProvider serializers
|
||||
) throws IOException {
|
||||
generator.writeStringField("key", value.getEntryKey());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue