Code example for Gson

Methods: toJson

0
     */ 
    public String defineStream(StreamDefinition streamDefinition)
            throws AgentException, MalformedStreamDefinitionException, StreamDefinitionException, 
            DifferentStreamDefinitionAlreadyDefinedException { 
        String sessionId = dataPublisherConfiguration.getSessionId();
        String streamId = eventPublisher.defineStream(sessionId, gson.toJson(streamDefinition));
        try { 
            Field field = StreamDefinition.class.getDeclaredField("streamId");
            field.setAccessible(true);
            field.set(streamDefinition, streamId);
        } catch (NoSuchFieldException e) {
 
        } catch (IllegalAccessException e) {
 
        } 
        return streamId;
    } 
 
    /** 
     * Finding already existing stream's Id to publish data 
Experience pair programming with AI  Get Codota for Java