Skip to content

Instantly share code, notes, and snippets.

View re-mscho's full-sized avatar

Martin Schoegler re-mscho

View GitHub Profile
@re-mscho
re-mscho / default_serializer.py
Created March 27, 2024 11:49
python default json serializer
def custom_serializer(obj):
if hasattr(obj, '__dict__'):
attributes = obj.__dict__
elif hasattr(obj, '__slots__'):
attributes = {slot: getattr(obj, slot) for slot in obj.__slots__}
else:
attributes = {attr: getattr(obj, attr) for attr in dir(obj) if not attr.startswith('__')}
# Convert Enum attributes to their values
return {key: value.name if isinstance(value, Enum) else value for key, value in attributes.items()}
#!/usr/bin/env groovy
@Grab('info.picocli:picocli-groovy:4.3.2')
import groovy.json.JsonSlurper
@Grab('org.yaml:snakeyaml:1.17')
import org.yaml.snakeyaml.Yaml
import picocli.CommandLine
import picocli.CommandLine.Help.Ansi
import java.util.concurrent.Callable