001package ball.persistence.entity; 002/*- 003 * ########################################################################## 004 * Persistence Implementation (Hibernate) 005 * $Id: JSONEntityTypeMap.java 5285 2020-02-05 04:23:21Z ball $ 006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/ball-persistence/trunk/src/main/java/ball/persistence/entity/JSONEntityTypeMap.java $ 007 * %% 008 * Copyright (C) 2016 - 2020 Allen D. Ball 009 * %% 010 * Licensed under the Apache License, Version 2.0 (the "License"); 011 * you may not use this file except in compliance with the License. 012 * You may obtain a copy of the License at 013 * 014 * http://www.apache.org/licenses/LICENSE-2.0 015 * 016 * Unless required by applicable law or agreed to in writing, software 017 * distributed under the License is distributed on an "AS IS" BASIS, 018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 019 * See the License for the specific language governing permissions and 020 * limitations under the License. 021 * ########################################################################## 022 */ 023import ball.databind.JSONBeanTypeMap; 024import com.fasterxml.jackson.core.ObjectCodec; 025import com.fasterxml.jackson.databind.JsonNode; 026import com.fasterxml.jackson.databind.ObjectMapper; 027import com.fasterxml.jackson.databind.SerializationFeature; 028import java.io.IOException; 029import lombok.NoArgsConstructor; 030 031import static lombok.AccessLevel.PROTECTED; 032 033/** 034 * {@link JSONEntity} {@link JSONBeanTypeMap}. 035 * 036 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball} 037 * @version $Revision: 5285 $ 038 */ 039@NoArgsConstructor(access = PROTECTED) 040public abstract class JSONEntityTypeMap extends JSONBeanTypeMap { 041 private static final long serialVersionUID = 4058644186117804634L; 042 043 @Override 044 protected void initialize(Object object, 045 ObjectCodec codec, 046 JsonNode node) throws IOException { 047 super.initialize(object, codec, node); 048 049 if (object instanceof JSONEntity) { 050 JSONEntity entity = (JSONEntity) object; 051 052 entity.setJson(((ObjectMapper) codec).writeValueAsString(node)); 053 } 054 } 055}