001/** 002 * Copyright (C) 2006-2025 Talend Inc. - www.talend.com 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.talend.sdk.component.runtime.input; 017 018import javax.json.Json; 019import javax.json.JsonObject; 020import javax.json.bind.Jsonb; 021import javax.json.bind.annotation.JsonbProperty; 022import javax.json.bind.spi.JsonbProvider; 023 024import lombok.AllArgsConstructor; 025import lombok.Data; 026 027@Data 028@AllArgsConstructor 029public class CheckpointState { 030 031 public static final String CHECKPOINT_KEY = "$checkpoint"; 032 033 public static final String VERSION_KEY = "__version"; 034 035 private static final Jsonb JSONB = JsonbProvider.provider().create().build(); 036 037 @JsonbProperty(VERSION_KEY) 038 private int version; 039 040 private Object state; 041 042 public JsonObject toJson() { 043 return Json.createObjectBuilder() 044 .add(CHECKPOINT_KEY, Json.createObjectBuilder(JSONB.fromJson(JSONB.toJson(state), JsonObject.class)) 045 .add(VERSION_KEY, version) 046 .build()) 047 .build(); 048 } 049}