Skip to content

Commit

Permalink
Add last_update_time
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <cwperx@amazon.com>
  • Loading branch information
cwperks committed Jan 2, 2025
1 parent a1b4d09 commit b779735
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opensearch.security.sample.resource;

import java.io.IOException;
import java.time.Instant;

import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.core.xcontent.XContentParserUtils;
Expand All @@ -20,10 +21,24 @@ public SampleResource parse(XContentParser parser, String id) throws IOException
case "name":
resource.setName(parser.text());
break;
case "last_update_time":
resource.setLastUpdateTime(parseInstantValue(parser));
break;
default:
XContentParserUtils.throwUnknownToken(parser.currentToken(), parser.getTokenLocation());
}
}
return resource;
}

private Instant parseInstantValue(XContentParser parser) throws IOException {
if (XContentParser.Token.VALUE_NULL.equals(parser.currentToken())) {
return null;
}
if (parser.currentToken().isValue()) {
return Instant.ofEpochMilli(parser.longValue());
}
XContentParserUtils.throwUnknownToken(parser.currentToken(), parser.getTokenLocation());
return null;
}
}

0 comments on commit b779735

Please sign in to comment.