-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refine Serialization implementation
- add StateSerializer abstract class that owns a StateFactory - refactor tests, samples and how-tos accordly work on #29
- Loading branch information
1 parent
72d0e33
commit 199ae8d
Showing
17 changed files
with
370 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
core-jdk8/src/main/java/org/bsc/langgraph4j/serializer/StateSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.bsc.langgraph4j.serializer; | ||
|
||
import lombok.NonNull; | ||
import org.bsc.langgraph4j.state.AgentState; | ||
import org.bsc.langgraph4j.state.AgentStateFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public abstract class StateSerializer<State extends AgentState> implements Serializer<State> { | ||
|
||
private final AgentStateFactory<State> stateFactory; | ||
|
||
protected StateSerializer( @NonNull AgentStateFactory<State> stateFactory) { | ||
this.stateFactory = stateFactory; | ||
} | ||
|
||
public final AgentStateFactory<State> stateFactory() { | ||
return stateFactory; | ||
} | ||
|
||
public final State stateOf( @NonNull Map<String,Object> data) { | ||
return stateFactory.apply(data); | ||
} | ||
|
||
public final State cloneObject( @NonNull Map<String,Object> data) throws IOException, ClassNotFoundException { | ||
return cloneObject( stateFactory().apply(data) ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.