Skip to content

Instantly share code, notes, and snippets.

@fcaylus
Created September 20, 2021 08:27
Show Gist options
  • Save fcaylus/07b86ab379d7d0f5562dbba522655090 to your computer and use it in GitHub Desktop.
Save fcaylus/07b86ab379d7d0f5562dbba522655090 to your computer and use it in GitHub Desktop.
JSON to Smile encoding in Kotlin
val json = "{\"a\":1}"
val builder = SmileXContent.contentBuilder()
val parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json)
builder.copyCurrentStructure(parser)
Files.write(Paths.get("test.sml"), BytesReference.toBytes(BytesReference.bytes(builder)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment