001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.marshall.jena; 018 019/** 020 * Subclass of {@link RdfSerializer} for serializing POJOs to N-Triples notation. 021 * 022 * <p> 023 * Produces one RDF triple per line in W3C N-Triples format. Simple, line-oriented, and easy to parse. 024 * 025 * <h5 class='figure'>Examples:</h5> 026 * <p class='bjava'> 027 * <jc>// Serialize a bean to N-Triples string.</jc> 028 * Person <jv>person</jv> = <jk>new</jk> Person(<js>"Alice"</js>, 30); 029 * String <jv>nTriples</jv> = NTripleSerializer.<jsf>DEFAULT</jsf>.write(<jv>person</jv>); 030 * </p> 031 * <p class='bjava'> 032 * <jc>// Or use the NTriple marshaller for convenience.</jc> 033 * String <jv>nTriples</jv> = NTriple.<jsf>DEFAULT</jsf>.write(<jv>person</jv>); 034 * </p> 035 * <p class='bjava'> 036 * <jc>// Custom serializer with swaps.</jc> 037 * NTripleSerializer <jv>s</jv> = NTripleSerializer.create().swaps(DateSwap.<jk>class</jk>).build(); 038 * String <jv>nTriples</jv> = <jv>s</jv>.write(<jv>person</jv>); 039 * </p> 040 * 041 * <h5 class='figure'>Example output (bean with name/age):</h5> 042 * <p class='bcode'> 043 * <...> <.../name> "Alice" . 044 * <...> <.../age> "30"^^<http://www.w3.org/2001/XMLSchema#int> . 045 * </p> 046 * 047 * <h5 class='figure'>Complex (nested address + array):</h5> 048 * <p class='bcode'> 049 * <...> <.../name> "Alice" . 050 * <...> <.../age> "30"^^... . 051 * <...> <.../address> <.../address> . 052 * <.../address> <.../street> "123 Main St" . 053 * <.../address> <.../city> "Boston" . 054 * <.../address> <.../state> "MA" . 055 * </p> 056 * 057 * <h5 class='section'>Notes:</h5><ul> 058 * <li class='note'>This class is thread safe and reusable. 059 * </ul> 060 * 061 * <h5 class='section'>See Also:</h5><ul> 062 * <li class='link'>{doc jmr.RdfDetails} 063 * </ul> 064 */ 065@SuppressWarnings({ 066 "java:S110" // Deep inheritance inherent to the RDF serializer hierarchy. 067}) 068public class NTripleSerializer extends RdfSerializer { 069 070 /** Default N-Triple serializer, all default settings.*/ 071 public static final NTripleSerializer DEFAULT = new NTripleSerializer(create()); 072 073 /** 074 * Creates a new builder for this object. 075 * 076 * @return A new builder. 077 */ 078 @SuppressWarnings({ 079 "java:S1452", // Builder<?> wildcard return intentional; callers chain via fluent API without needing the concrete type 080 "java:S9149" // Public Juneau DSL factory; hiding parent create() is intentional. 081 }) 082 public static RdfSerializer.Builder<?> create() { 083 return RdfSerializer.create().ntriple(); 084 } 085 086 /** 087 * Constructor. 088 * 089 * @param builder The builder for this object. 090 * <br>Cannot be <jk>null</jk>. 091 */ 092 public NTripleSerializer(RdfSerializer.Builder<?> builder) { 093 super(builder.ntriple()); 094 } 095}