001package io.ebean.text.json; 002 003import com.fasterxml.jackson.core.JsonParser; 004import io.ebean.bean.PersistenceContext; 005 006/** 007 * Provides a JSON reader that can hold a persistence context and load context while reading JSON. 008 * <p> 009 * This provides a mechanism such that an object loaded from JSON can have unique instances 010 * by using a persistence context and also support further lazy loading (via a load context). 011 * </p> 012 */ 013public interface JsonBeanReader<T> { 014 015 /** 016 * Read the JSON into given bean. Will update existing properties. 017 */ 018 T read(T target); 019 020 /** 021 * Read the JSON returning a bean. 022 */ 023 default T read() { 024 return read(null); 025 } 026 027 /** 028 * Create a new reader taking the context from the existing one but using a new JsonParser. 029 */ 030 JsonBeanReader<T> forJson(JsonParser moreJson); 031 032 /** 033 * Add a bean explicitly to the persistence context. 034 */ 035 void persistenceContextPut(Object beanId, T currentBean); 036 037 /** 038 * Return the persistence context if one is being used. 039 */ 040 PersistenceContext getPersistenceContext(); 041 042}