- 
                Notifications
    You must be signed in to change notification settings 
- Fork 50
feat: add hook data #1587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
            toddbaert
  merged 23 commits into
  open-feature:main
from
open-feature-forking:feat/hook-data
  
      
      
   
  Sep 15, 2025 
      
    
  
     Merged
                    feat: add hook data #1587
Changes from 14 commits
      Commits
    
    
            Show all changes
          
          
            23 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      13dbeee
              
                Added hook data
              
              
                mdxabu 549e97c
              
                to support null values while maintaining thread safety, you must avoi…
              
              
                mdxabu c06c679
              
                Build successfully runned:spotless plugin
              
              
                mdxabu e00885f
              
                Merge branch 'main' into main
              
              
                aepfli e0ad9d9
              
                Merge branch 'main' into main
              
              
                beeme1mr f4c97ee
              
                Merge branch 'main' into main
              
              
                aepfli ce1a60b
              
                fixup: fix comment
              
              
                aepfli bc883c5
              
                fixup: remove synchronized map
              
              
                aepfli 1339f2f
              
                fixup: removed unneeded import
              
              
                aepfli c66e2c8
              
                fixup: spotless
              
              
                aepfli d9ebe63
              
                Update src/main/java/dev/openfeature/sdk/HookData.java
              
              
                mdxabu f3ea94d
              
                Update src/main/java/dev/openfeature/sdk/HookData.java
              
              
                mdxabu 81f2e4f
              
                feat: add support for hook data sharing between stages
              
              
                alexandraoberaigner 6d4f700
              
                fixup: tests
              
              
                aepfli a4fc956
              
                fixup: pr comments and extraction of own pair class
              
              
                aepfli 0dee929
              
                feat: add HookContext decorator
              
              
                aepfli 1de7aea
              
                fixup: add default method for interface
              
              
                aepfli 52cbaa7
              
                feat: performance boost
              
              
                aepfli 0b224de
              
                feat: performance improvements
              
              
                aepfli 711e0be
              
                fixup: lazy init
              
              
                aepfli c3f8f36
              
                fixup: pr comments
              
              
                aepfli 88afd35
              
                Merge branch 'main' into feat/hook-data
              
              
                aepfli 76445d2
              
                Merge branch 'main' into feat/hook-data
              
              
                aepfli File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or 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 hidden or 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,75 @@ | ||
| package dev.openfeature.sdk; | ||
|  | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|  | ||
| /** | ||
| * Hook data provides a way for hooks to maintain state across their execution stages. | ||
| * Each hook instance gets its own isolated data store that persists only for the duration | ||
| * of a single flag evaluation. | ||
| */ | ||
| public interface HookData { | ||
|  | ||
| /** | ||
| * Sets a value for the given key. | ||
| * | ||
| * @param key the key to store the value under | ||
| * @param value the value to store | ||
| */ | ||
| void set(String key, Object value); | ||
|  | ||
| /** | ||
| * Gets the value for the given key. | ||
| * | ||
| * @param key the key to retrieve the value for | ||
| * @return the value, or null if not found | ||
| */ | ||
| Object get(String key); | ||
|  | ||
| /** | ||
| * Gets the value for the given key, cast to the specified type. | ||
| * | ||
| * @param <T> the type to cast to | ||
| * @param key the key to retrieve the value for | ||
| * @param type the class to cast to | ||
| * @return the value cast to the specified type, or null if not found | ||
| * @throws ClassCastException if the value cannot be cast to the specified type | ||
| */ | ||
| <T> T get(String key, Class<T> type); | ||
|  | ||
| /** | ||
| * Default implementation uses a HashMap. | ||
| */ | ||
| static HookData create() { | ||
| return new DefaultHookData(); | ||
| } | ||
|  | ||
| /** | ||
| * Default implementation of HookData. | ||
| */ | ||
| public class DefaultHookData implements HookData { | ||
| private final Map<String, Object> data = new HashMap<>(); | ||
|  | ||
| @Override | ||
| public void set(String key, Object value) { | ||
| data.put(key, value); | ||
| } | ||
|  | ||
| @Override | ||
| public Object get(String key) { | ||
| return data.get(key); | ||
| } | ||
|  | ||
| @Override | ||
| public <T> T get(String key, Class<T> type) { | ||
| Object value = data.get(key); | ||
| if (value == null) { | ||
| return null; | ||
| } | ||
| if (!type.isInstance(value)) { | ||
| throw new ClassCastException("Value for key '" + key + "' is not of type " + type.getName()); | ||
| } | ||
| return type.cast(value); | ||
| } | ||
| } | ||
| } | ||
  
    
      This file contains hidden or 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 hidden or 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.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.