Skip to content
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

Add Docs about anything that is being added into Monog must have a converter #58

Open
StephenOTT opened this issue Jan 13, 2019 · 1 comment

Comments

@StephenOTT
Copy link
Owner

Note that a Document.class does not actually require a _id. So when using a PUSH directly into a Array inside of a existing document, the Converter only requires that the Document format is used to is bypasses any Spring conversion utilities

such as

 @WritingConverter
    public class MongoWriterConverter implements Converter<TaxiiStatusFailureResource, Document> {
        public Document convert(final TaxiiStatusFailureResource object) {
            try {
                return Document.parse(TaxiiParsers.getMongoMapper().writeValueAsString(object));
            } catch (JsonProcessingException e) {
                throw new IllegalStateException(e);
            }
        }
    }

    @ReadingConverter
    public class MongoReaderConverter implements Converter<Document, TaxiiStatusFailureResource> {
        public TaxiiStatusFailureResource convert(final Document object) {
            try {
                return TaxiiParsers.getMongoMapper().readValue(object.toJson(), TaxiiStatusFailureResource.class);
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }
    }
@StephenOTT
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant