Class JsonRenderer

  • All Implemented Interfaces:
    com.yahoo.component.Component, java.lang.Cloneable, java.lang.Comparable<com.yahoo.component.Component>

    public class JsonRenderer
    extends com.yahoo.processing.rendering.AsynchronousSectionedRenderer<Result>
    JSON renderer for search results.
    Author:
    Steinar Knutsen, bratseth
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  JsonRenderer.FieldConsumer
      Received callbacks when fields of hits are encountered.
    • Field Summary

      • Fields inherited from class com.yahoo.component.AbstractComponent

        isDeconstructable
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonRenderer()  
      JsonRenderer​(java.util.concurrent.Executor executor)
      Creates a json renderer using a custom executor.
    • Constructor Detail

      • JsonRenderer

        public JsonRenderer()
      • JsonRenderer

        public JsonRenderer​(java.util.concurrent.Executor executor)
        Creates a json renderer using a custom executor. Using a custom executor is useful for tests to avoid creating new threads for each renderer registry.
    • Method Detail

      • createJsonCodec

        protected static com.fasterxml.jackson.databind.ObjectMapper createJsonCodec()
        Create the codec used for rendering instances of TreeNode. This method will be invoked when creating the first renderer instance, but not for each fresh clone used by individual results.
        Returns:
        an object mapper for the internal JsonFactory
      • init

        public void init()
        Overrides:
        init in class com.yahoo.processing.rendering.AsynchronousSectionedRenderer<Result>
      • beginResponse

        public void beginResponse​(java.io.OutputStream stream)
                           throws java.io.IOException
        Specified by:
        beginResponse in class com.yahoo.processing.rendering.AsynchronousSectionedRenderer<Result>
        Throws:
        java.io.IOException
      • renderTrace

        protected void renderTrace​(com.yahoo.processing.execution.Execution.Trace trace)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • beginList

        public void beginList​(com.yahoo.processing.response.DataList<?> list)
                       throws java.io.IOException
        Specified by:
        beginList in class com.yahoo.processing.rendering.AsynchronousSectionedRenderer<Result>
        Throws:
        java.io.IOException
      • moreChildren

        protected void moreChildren()
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • renderHitGroupHead

        protected void renderHitGroupHead​(HitGroup hitGroup)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • renderErrors

        protected void renderErrors​(java.util.Set<ErrorMessage> errors)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • renderCoverage

        protected void renderCoverage()
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • renderHit

        protected void renderHit​(Hit hit)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • shouldRender

        protected boolean shouldRender​(Hit hit)
      • renderHitContents

        protected void renderHitContents​(Hit hit)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • renderAllFields

        protected void renderAllFields​(Hit hit)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • renderContinuations

        protected void renderContinuations​(java.util.Map<java.lang.String,​Continuation> continuations)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • renderGroupMetadata

        protected void renderGroupMetadata​(GroupId id)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • renderTotalHitCount

        protected void renderTotalHitCount​(Hit hit)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • data

        public void data​(com.yahoo.processing.response.Data data)
                  throws java.io.IOException
        Specified by:
        data in class com.yahoo.processing.rendering.AsynchronousSectionedRenderer<Result>
        Throws:
        java.io.IOException
      • endList

        public void endList​(com.yahoo.processing.response.DataList<?> list)
                     throws java.io.IOException
        Specified by:
        endList in class com.yahoo.processing.rendering.AsynchronousSectionedRenderer<Result>
        Throws:
        java.io.IOException
      • endResponse

        public void endResponse()
                         throws java.io.IOException
        Specified by:
        endResponse in class com.yahoo.processing.rendering.AsynchronousSectionedRenderer<Result>
        Throws:
        java.io.IOException
      • getEncoding

        public java.lang.String getEncoding()
        Specified by:
        getEncoding in class com.yahoo.processing.rendering.Renderer<Result>
      • getMimeType

        public java.lang.String getMimeType()
        Specified by:
        getMimeType in class com.yahoo.processing.rendering.Renderer<Result>
      • createFieldConsumer

        protected JsonRenderer.FieldConsumer createFieldConsumer​(com.fasterxml.jackson.core.JsonGenerator generator,
                                                                 boolean debugRendering)