public abstract class AbstractJackson2View extends AbstractView
AbstractView 実装の抽象基本クラス。Spring 4.3 の時点で、Jackson 2.6 以降と互換性があります。
| 修飾子と型 | フィールドと説明 |
|---|---|
protected boolean | updateContentLength |
DEFAULT_CONTENT_TYPEloggerPATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE| 修飾子 | コンストラクターと説明 |
|---|---|
protected | AbstractJackson2View(ObjectMapper objectMapper, StringSE contentType) |
| 修飾子と型 | メソッドと説明 |
|---|---|
protected ObjectSE | filterAndWrapModel(MapSE<StringSE, ObjectSE> model, HttpServletRequestEE request)MappingJacksonValue コンテナーでモデルをフィルターし、オプションでラップします。 |
protected abstract ObjectSE | filterModel(MapSE<StringSE, ObjectSE> model) 指定されたモデルから不要な属性を除外します。 |
JsonEncoding | getEncoding() このビューの JsonEncoding を返します。 |
ObjectMapper | getObjectMapper() このビューの ObjectMapper を返します。 |
protected void | prepareResponse(HttpServletRequestEE request, HttpServletResponseEE response) レンダリングのために指定されたレスポンスを準備します。 |
protected void | renderMergedOutputModel(MapSE<StringSE, ObjectSE> model, HttpServletRequestEE request, HttpServletResponseEE response) ビューを実際にレンダリングするには、サブクラスでこのメソッドを実装する必要があります。 |
void | setDisableCaching(boolean disableCaching) 生成された JSON のキャッシュを無効にします。 |
void | setEncoding(JsonEncoding encoding) このビューの JsonEncoding を設定します。 |
abstract void | setModelKey(StringSE modelKey) このビューによってレンダリングされるモデルの属性を設定します。 |
void | setObjectMapper(ObjectMapper objectMapper) このビューの ObjectMapper を設定します。 |
void | setPrettyPrint(boolean prettyPrint) 出力を書き込むときにデフォルトのプリティプリンターを使用するかどうか。 |
void | setUpdateContentLength(boolean updateContentLength) レスポンスの "Content-Length" ヘッダーを更新するかどうか。 |
protected void | writeContent(OutputStreamSE stream, ObjectSE object) 実際の JSON コンテンツをストリームに書き込みます。 |
protected void | writePrefix(JsonGenerator generator, ObjectSE object) メインコンテンツの前にプレフィックスを書きます。 |
protected void | writeSuffix(JsonGenerator generator, ObjectSE object) メインコンテンツの後にサフィックスを記述します。 |
addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestToExpose, getStaticAttributes, isExposePathVariables, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, toString, writeToResponsegetServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextgetApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContextcloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, waitSE, waitSE, waitSEprotected AbstractJackson2View(ObjectMapper objectMapper, StringSE contentType)
public void setObjectMapper(ObjectMapper objectMapper)
ObjectMapper を設定します。設定しない場合、デフォルトの ObjectMapper が使用されます。 カスタム構成された ObjectMapper を設定することは、JSON 直列化プロセスをさらに制御する 1 つの方法です。もう 1 つのオプションは、直列化する型に Jackson が提供するアノテーションを使用することです。この場合、カスタム構成の ObjectMapper は不要です。
public final ObjectMapper getObjectMapper()
ObjectMapper を返します。public void setEncoding(JsonEncoding encoding)
JsonEncoding を設定します。デフォルトでは、UTF-8 が使用されます。public final JsonEncoding getEncoding()
JsonEncoding を返します。public void setPrettyPrint(boolean prettyPrint)
ObjectMapper を次のように設定するためのショートカットです。ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
デフォルト値は false です。
public void setDisableCaching(boolean disableCaching)
デフォルトは true で、クライアントは生成された JSON をキャッシュできません。
public void setUpdateContentLength(boolean updateContentLength)
true に設定すると、コンテンツの長さを判別し、レスポンスの 'Content-Length' ヘッダーを設定するために、レスポンスがバッファーに入れられます。 デフォルト設定は false です。
protected void prepareResponse(HttpServletRequestEE request, HttpServletResponseEE response)
AbstractViewデフォルトの実装では、HTTPS 経由でダウンロードコンテンツを送信するときに IE バグの回避策が適用されます。
AbstractView の prepareResponse request - 現在の HTTP リクエスト response - 現在の HTTP レスポンス protected void renderMergedOutputModel(MapSE<StringSE,ObjectSE> model, HttpServletRequestEE request, HttpServletResponseEE response) throws ExceptionSE
AbstractView最初のステップは、リクエストの準備です。JSP の場合、これはモデルオブジェクトをリクエスト属性として設定することを意味します。2 番目のステップは、たとえば RequestDispatcher を介した JSP を含む、実際のビューのレンダリングです。
AbstractView の renderMergedOutputModel model - 静的な属性よりも動的な値が優先される、結合された出力マップ(非 null)request - 現在の HTTP リクエスト response - 現在の HTTP レスポンス ExceptionSE - レンダリングに失敗した場合 protected ObjectSE filterAndWrapModel(MapSE<StringSE,ObjectSE> model, HttpServletRequestEE request)
MappingJacksonValue コンテナーでモデルをフィルターし、オプションでラップします。model - renderMergedOutputModel(java.util.Map<java.lang.String, java.lang.Object>, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) に渡されるモデル request - 現在の HTTP リクエスト protected void writeContent(OutputStreamSE stream, ObjectSE object) throws IOExceptionSE
stream - 使用する出力ストリーム object - filterModel(java.util.Map<java.lang.String, java.lang.Object>) から返された、レンダリングされる値 IOExceptionSE - 書き込みに失敗した場合 public abstract void setModelKey(StringSE modelKey)
protected abstract ObjectSE filterModel(MapSE<StringSE,ObjectSE> model)
MapSE または単一の値オブジェクトのいずれかです。model - renderMergedOutputModel(java.util.Map<java.lang.String, java.lang.Object>, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) に渡されるモデル protected void writePrefix(JsonGenerator generator, ObjectSE object) throws IOExceptionSE
generator - コンテンツの書き込みに使用するジェネレーター。object - 出力メッセージに書き込むオブジェクト。IOExceptionSEprotected void writeSuffix(JsonGenerator generator, ObjectSE object) throws IOExceptionSE
generator - コンテンツの書き込みに使用するジェネレーター。object - 出力メッセージに書き込むオブジェクト。IOExceptionSE