### Install jspoon via Gradle Dependency Source: https://github.com/droidsonroids/jspoon/blob/master/README.md This snippet demonstrates how to add the jspoon library as a dependency to your project's `build.gradle` file, enabling its use in your Java application. ```Gradle dependencies { implementation 'pl.droidsonroids:jspoon:1.3.2' } ``` -------------------------------- ### Parse HTML Content to Java Object using jspoon HtmlAdapter Source: https://github.com/droidsonroids/jspoon/blob/master/README.md This example demonstrates the core functionality of jspoon: creating an `HtmlAdapter` for a defined class and parsing an HTML string into an instance of that class. It includes the sample HTML content and the expected parsed output. ```Java String htmlContent = "
" + "

Title

" + "" + "" + "
"; Jspoon jspoon = Jspoon.create(); HtmlAdapter htmlAdapter = jspoon.adapter(Page.class); Page page = htmlAdapter.fromHtml(htmlContent); //title = "Title"; intList = [1, 3]; imageSource = "image.bmp" ``` -------------------------------- ### Configure Locale and Default Values in jspoon Selectors Source: https://github.com/droidsonroids/jspoon/blob/master/README.md This example demonstrates how to override the default Java `Locale` for parsing numbers and dates using the `languageTag` parameter in `@Format`, and how to provide a `defValue` in `@Selector` for fields when the corresponding HTML element is not found. ```Java @Format(languageTag = "pl") @Selector(value = "div > p > span") Double pi; //3,14 will be parsed ``` ```Java @Selector(value = "div > p > span", defValue = "NO_TEXT") String text; ``` -------------------------------- ### Define Java Class for HTML Parsing with @Selector Source: https://github.com/droidsonroids/jspoon/blob/master/README.md This Java class illustrates how to annotate fields with `@Selector` to map specific HTML elements to Java object properties. It includes examples for extracting text content, lists of values, and attribute values. ```Java class Page { @Selector("#title") String title; @Selector("li.a") List intList; @Selector(value = "#image1", attr = "src") String imageSource; } ``` -------------------------------- ### Apply Regex and Date Formatting in jspoon @Selector Source: https://github.com/droidsonroids/jspoon/blob/master/README.md These snippets show how to use the `regex` parameter within the `@Selector` annotation for pattern matching and the `@Format` annotation for specifying date formats when parsing HTML content into Java objects. A complete usage example is provided. ```Java class Page { @Selector(value = "#numbers", regex = "([a-z]+),") String matchedNumber; } ``` ```Java class Page { @Format(value = "HH:mm:ss dd.MM.yyyy") @Selector(value = "#date") Date date; } ``` ```Java String htmlContent = "13:30:12 14.07.2017" + "ONE, TwO, three,"; Jspoon jspoon = Jspoon.create(); HtmlAdapter htmlAdapter = jspoon.adapter(Page.class); Page page = htmlAdapter.fromHtml(htmlContent);//date = Jul 14, 2017 13:30:12; matchedNumber = "three"; ``` -------------------------------- ### Apply Custom ElementConverter in jspoon Model Source: https://github.com/droidsonroids/jspoon/blob/master/README.md This example demonstrates how to apply a custom `ElementConverter` to a field within a jspoon model using the `converter` parameter in the `@Selector` annotation, enabling the use of custom parsing logic for that specific field. ```Java public class Model { @Selector(value = "#id", converter = JoinChildrenClassConverter::class) String childrenText; } ``` -------------------------------- ### Add Jspoon Retrofit Converter Dependency Source: https://github.com/droidsonroids/jspoon/blob/master/retrofit-converter-jspoon/README.md Adds the `converter-jspoon` library as an implementation dependency to your Android or Java project's `build.gradle` file, enabling Retrofit to use jspoon for HTML parsing. This allows you to integrate the converter into your Retrofit builder. ```Gradle dependencies { implementation 'pl.droidsonroids.retrofit2:converter-jspoon:1.3.2' } ``` -------------------------------- ### Implement Custom ElementConverter for Advanced HTML Parsing Source: https://github.com/droidsonroids/jspoon/blob/master/README.md This snippet illustrates how to create a custom `ElementConverter` by extending the `ElementConverter` class. This allows for defining complex and custom parsing logic for HTML elements beyond the built-in capabilities of jspoon. ```Java public class JoinChildrenClassConverter implements ElementConverter { @Override public String convert(Element node, Selector selector) { return node.children().stream().map(Element::text).collect(Collectors.joining(", ")); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.