DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • From On-Prem to SaaS
  • Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  • Cucumber Selenium Tutorial: A Comprehensive Guide With Examples and Best Practices

Trending

  • From On-Prem to SaaS
  • Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  • Cucumber Selenium Tutorial: A Comprehensive Guide With Examples and Best Practices
  1. DZone
  2. Coding
  3. Frameworks
  4. A Simple Scala Validation Framework

A Simple Scala Validation Framework

Wille Faler user avatar by
Wille Faler
·
Jul. 03, 11 · News
Like (0)
Save
Tweet
Share
8.30K Views

Join the DZone community and get the full member experience.

Join For Free

I was on the lookout for Scala validation frameworks, and I couldn’t readily find any that where not part of/dependent on some web- or other framework. Furthermore, I didn’t want to use a Java validation framework with all the compromises that would entail, so realising it would be relatively trivial to do one in Scala, I knocked one together myself in a few evenings.

Hey presto, here it is! (bundled with a few other utility classes). It should be relatively easy from the README section further down on the page linked to how to use it (the code is built with SBT). However to explain a few things I wanted to achieve by writing my own:

  • Validate any object or object-graph with the same concise API: Well, duh, obviously. :)
  • No external dependencies and deployable/usable in any tier of an application: from frontend to backend.
  • Separate the concerns of validation and domain: Hibernate Validator and the Bean Validator JSR’s use annotations, which works in some respects, but is inappropriate in many scenarios. For instance you may want to validate an address differently depending on what country context it is in.
  • Use the power of functions in Scala: Many if not most Java validation frameworks use annotations, reflections and various other tricks. In Scala this is not necessary, as a lot of it can be circumvented simply by using Scala’s functional programming aspects.
  • Separate the concerns of validation and error message loading: At the moment there is a classpath resource MessageResolver defined that supports localisation, however you can very easily roll your own. You may want to manage messages in different ways (property-files, xml-files, in a database etc).
  • Composability: Use as much or as little of the framework, roll your own implementations and/or hook into the validation framework at the level of abstraction you find useful.

This is something I’ve pretty much put together in a few evenings, so there is probably room for cleaning up and improving the code, though hopefully it is somewhat bug free at less than 200 lines of code with 18 unit tests.. Further, I’m just starting to dive deeper into the functional aspects of Scala, so my “Java damage” may still shine through.

But feedback is most welcome, so go get the source from GitHub!

Scala (programming language) Framework

Published at DZone with permission of Wille Faler, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • From On-Prem to SaaS
  • Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
  • Building a Flask Web Application With Docker: A Step-by-Step Guide
  • Cucumber Selenium Tutorial: A Comprehensive Guide With Examples and Best Practices

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: